Learn R Programming

collections (version 0.1.0)

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()
Dict$set(key, value)
Dict$get(key, default = NULL)
Dict$remove(key)
Dict$pop(key, default = NULL)
Dict$has(key)
Dict$keys()
Dict$values()
Dict$update(d)
Dict$size()
Dict$as_list()

  • key: any R object, key of the item

  • value: any R object, value of the item

  • default: 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()
d$set("apple", 5)
d$set("orange", 10)
d$set("banana", 3)
d$get("apple")
d$as_list()  # unordered
d$pop("orange")
d$as_list()  # "orange" is removed
# }

Run the code above in your browser using DataLab