ordered_dict {collections}R Documentation

Ordered Dictionary

Description

ordered_dict creates an ordered dictionary.

Usage

ordered_dict(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, silent = FALSE)
.$pop(key, default)
.$popitem(last = TRUE)
.$has(key)
.$keys()
.$values()
.$update(d)
.$clear()
.$size()
.$as_list()
.$print()

See Also

dict

Examples

d <- ordered_dict(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

[Package collections version 0.3.5 Index]