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.
R6::R6Class object.
d = Dictionary$new()
get(key, ...)
(character(1)
, ...) -> any
Retrieves object with key key
from the dictionary.
Additional arguments are passed to the stored object during construction.
mget(keys, ...)
(character()
, ...) -> named list()
Returns objects with keys keys
in a list named with keys
.
Additional arguments are passed to the stored objects during construction.
has(keys)
character()
-> logical()
Returns a logical vector with TRUE
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 expression pattern
.
If pattern
is NULL
(default), all keys are returned.
add(key, value, ..., required_args = character())
(character(1)
, any
, ..., character()
) -> self
Adds object value
to the dictionary with key key
, potentially overwriting a previously stored item.
Additional arguments in ...
are used as default arguments for value
during construction.
If the object cannot be constructed without additional arguments, the require argument names should be provided in required_args
.
remove(keys)
character()
-> self
Removes objects with keys keys
from the dictionary.
required_args(key)
(character(1)
) -> character()
Returns the names of arguments required to construct the object.
as.data.table(d)
Dictionary -> data.table::data.table()
Converts the dictionary to a data.table::data.table()
.
# NOT RUN {
d = Dictionary$new()
d$add("a", 1)
d$add("b", 2)
d$keys()
d$get("a")
d$mget(c("a", "b"))
# }
Run the code above in your browser using DataCamp Workspace