A key-value store for R6::R6 objects. On retrieval of an object, the following applies:
If the object is a
R6ClassGenerator, it is initialized with
If the object is a function, it is called and must return an instance of a R6::R6 object.
If the object is an instance of a R6 class, it is returned as-is.
Default argument required for construction can be stored alongside their constructors by passing them to
d = Dictionary$new()
character(), ...) -> named
Returns objects with keys
keys in a list named with
Additional arguments must be named and are passed to the constructors of the stored objects.
add(key, value, ..., required_args = character())
value to the dictionary with key
key, potentially overwriting a previously stored item.
Additional arguments in
... must be named and are passed as default arguments to
value during construction.
The names of all additional arguments which are mandatory for construction and missing in
... should be listed in
library(R6) item1 = R6Class("Item", public = list(x = 1)) item2 = R6Class("Item", public = list(x = 2)) d = Dictionary$new() d$add("a", item1) d$add("b", item2) d$add("c", item1$new()) d$keys()#>  "a" "b" "c"d$get("a")#> <Item> #> Public: #> clone: function (deep = FALSE) #> x: 1#> $a #> <Item> #> Public: #> clone: function (deep = FALSE) #> x: 1 #> #> $b #> <Item> #> Public: #> clone: function (deep = FALSE) #> x: 2 #>