Learn R Programming

collections (version 0.1.6)

Dict: Dictionary

Description

The Dict class creates an ordinary (unordered) dictionary. The key-value pairs are stored in an R environment.

Usage

Dict

Arguments

Format

An object of class R6ClassGenerator of length 24.

Usage

Dict$new(items = NULL)
Dict$set(key, value)
Dict$get(key, default)
Dict$remove(key)
Dict$pop(key, default)
Dict$has(key)
Dict$keys()
Dict$values()
Dict$update(d)
Dict$clear()
Dict$size()
Dict$as_list()

  • items: initialization list

  • key: any R object, key of the item

  • value: any R object, value of the item

  • default: optional, the default value of an item if the key is not found

See Also

OrderedDict and OrderedDictL

Examples

Run this code
# NOT RUN {
d <- Dict$new(list(apple = 5, orange = 10))
d$set("banana", 3)
d$get("apple")
d$as_list()  # unordered
d$pop("orange")
d$as_list()  # "orange" is removed
d$set("orange", 3)$set("pear", 7)  # chain methods
# }

Run the code above in your browser using DataLab