Learn R Programming

collections (version 0.2.5)

OrderedDictL: Ordered Dictionary (R implementation)

Description

The OrderedDictL function creates an ordered dictionary. Pure R implementation for benchmarking.

Usage

OrderedDictL(items = NULL, keys = NULL)

Arguments

items

a list of items

keys

a list of keys, use names(items) if NULL

Details

Following methods are exposed:

.$set(key, value)
.$get(key, default)
.$remove(key)
.$pop(key, default)
.$popitem(last = TRUE)
.$has(key)
.$keys()
.$values()
.$update(d)
.$clear()
.$size()
.$as_list()
.$print()
  • 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

  • d: an OrderedDict or OrderedDictL

See Also

Dict and OrderedDict

Examples

Run this code
# NOT RUN {
d <- OrderedDictL(list(apple = 5, orange = 10))
d$set("banana", 3)
d$get("apple")
d$as_list()  # the order the item is preserved
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