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.

Format

R6::R6Class object.

Construction

d = Dictionary$new()

Methods

  • 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 is not constructible 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.

S3 methods

See also

Examples

d = Dictionary$new() d$add("a", 1) d$add("b", 2) d$keys()
#> [1] "a" "b"
d$get("a")
#> [1] 1
d$mget(c("a", "b"))
#> $a #> [1] 1 #> #> $b #> [1] 2 #>