Dictionary
Key-Value Storage
A simple key-value store for R6::R6 generator objects. On retrieval of an object, the following applies:
R6 Factories (objects of class
R6ClassGenerator
) are initialized.Functions are called and must return an instance of a R6::R6 object.
Other objects are returned as-is.
- Keywords
- datasets
Format
R6::R6Class object.
Construction
d = Dictionary$new()
Methods
get(key, ...)
(character(1)
, ...) ->any
Retrieves object with keykey
from the dictionary. Additional arguments are passed to the stored object during construction.mget(keys, ...)
(character()
, ...) -> namedlist()
Returns objects with keyskeys
in a list named withkeys
. Additional arguments are passed to the stored objects during construction.has(keys)
character()
->logical()
Returns a logical vector withTRUE
at its i-th position if the i-th key exists.keys(pattern = NULL)
character(1)
->character()
Returns all keys which comply to the regular expressionpattern
. Ifpattern
isNULL
(default), all keys are returned.add(key, value, ..., required_args = character())
(character(1)
,any
, ...,character()
) ->self
Adds objectvalue
to the dictionary with keykey
, potentially overwriting a previously stored item. Additional arguments in...
are used as default arguments forvalue
during construction. If the object cannot be constructed without additional arguments, the require argument names should be provided inrequired_args
.remove(keys)
character()
->self
Removes objects with keyskeys
from the dictionary.required_args(key)
(character(1)
) ->character()
Returns the names of arguments required to construct the object.
S3 methods
as.data.table(d)
Dictionary ->data.table::data.table()
Converts the dictionary to adata.table::data.table()
.
Examples
# NOT RUN {
d = Dictionary$new()
d$add("a", 1)
d$add("b", 2)
d$keys()
d$get("a")
d$mget(c("a", "b"))
# }