The Dict() resembles Python's dict type, and is implemented
as a specialized associative Container().
For the standard S3 interface, see dict().
container::Iterable -> container::Container -> Dict
Inherited methods
container::Iterable$iter()container::Container$at()container::Container$at2()container::Container$clear()container::Container$count()container::Container$delete()container::Container$delete_at()container::Container$discard()container::Container$empty()container::Container$get_compare_fun()container::Container$has()container::Container$has_name()container::Container$is_empty()container::Container$length()container::Container$names()container::Container$peek_at()container::Container$peek_at2()container::Container$pop()container::Container$print()container::Container$rename()container::Container$replace_at()container::Container$size()container::Container$type()
new()Dict constructor
Dict$new(...)...initial elements put into the Dict
returns the Dict
add()If name not yet in Dict, insert value at name,
otherwise signal an error.
Dict$add(name, value)namecharacter variable name under which to store value.
valuethe value to be added to the Dict.
the Dict object
discard_at()Discard value at given index. If index is not found, the operation is ignored.
Dict$discard_at(index)indexcharacter or numeric index
the Dict object
keycharacter name of key.
If key in Dict, return value at key, else throw error.
keys()Get all keys.
Dict$keys()character vector of all keys.
keycharacter name of key.
If key in Dict, remove it, otherwise raise an error.
replace()Replace one element by another element.
Search for occurence of old and, if found, replace it by new.
If old does not exist, an error is signaled.
Dict$replace(old, new)oldelement to be replaced
newelement to be put instead of old
the Dict object
set()This function is deprecated. Use replace() instead.
Dict$set(key, value, add = FALSE)keycharacter name of key.
valuethe value to be set
addlogical if TRUE the value is set regardless whether
key already exists in Dict.
returns the Dict
sort()Sort elements according to their keys. This function is deprecated as keys are now always sorted.
Dict$sort(decr = FALSE)decrlogical if TRUE sort in decreasing order.
returns the Dict
update()Add elements of other to this if the name is
not in the Dict and update elements with existing names.
Dict$update(other)otherIterable object used to update this.
returns the updated Dict object.
values()Get Container values
Dict$values()a copy of all elements in a list
clone()The objects of this class are cloneable with this method.
Dict$clone(deep = FALSE)deepWhether to make a deep clone.
This class inherits from class Container() and overwrides some
methods to account for the associative key-value pair semantic.
Internally, all key-value pairs are stored in a hash-table and the
elements are always sorted lexicographically by their keys.
Container(), dict()
d = Dict$new(o = "one", na = NA, a = 1)
d
d$keys()
d$add("li", list(1, 2))
d$discard_at("na")
d$replace(1, 9)
d2 = Dict$new(a = 0, b = 1)
d$update(d2)
Run the code above in your browser using DataLab