dict
creates an ordinary (unordered) dictionary (a.k.a. hash).
dict(items = NULL, keys = NULL)
items | a list of items |
---|---|
keys | a list of keys, use |
Following methods are exposed:
.$set(key, value) .$get(key, default) .$remove(key, silent = FALSE) .$pop(key, default) .$has(key) .$keys() .$values() .$update(d) .$clear() .$size() .$as_list() .$print()
key
: a scalar character, an atomic vector, an enviroment or a function
value
: any R object, value of the item
default
: optional, the default value of an item if the key is not found
d
: a dict object
#> [1] 5d$as_list() # unordered#> $apple #> [1] 5 #> #> $orange #> [1] 10 #> #> $banana #> [1] 3 #>d$pop("orange")#> [1] 10d$as_list() # "orange" is removed#> $apple #> [1] 5 #> #> $banana #> [1] 3 #>d$set("orange", 3)$set("pear", 7) # chain methods # vector indexing d$set(c(1L, 2L), 3)$set(LETTERS, 26) d$get(c(1L, 2L)) # 3#> [1] 3#> [1] 26#> [1] 1#> [1] 2