Dictionaries are essential objects in other object-oriented languages, such as Python. The primary function of a dictionary is to store items in a key-value pair. Where the key is the name of the item and the value is the value. This object contains all the 'usual' methods that would be found in other languages, including setting and getting values, adding and removing items, and containedness checks.
keys
None -> character()
Get dictionary keys.
values
None -> list()
Get dictionary values.
items
list() -> self
/ None -> list()
If x
is missing then returns the dictionary items.
If x
is not missing then used to set items in the dictionary.
length
None -> integer(1)
Get dictionary length as number of items.
typed
None -> logical(1)
Get if the dictionary is typed (TRUE
) or not (FALSE
).
types
None -> character()
Get the dictionary types (NULL if un-typed).
new()
Constructs a Dictionary
object.
Dictionary$new(..., x = list(...), types = NULL)
...
(ANY
)
Named arguments with names corresponding to the items to add to the
dictionary, where the keys are the names and the values are the
elements. Names must be unique.
x
(list()
)
A named list with the names corresponding to the items to add to the
dictionary, where the keys are the list names and the values are the
list elements. Names must be unique.
types
(character()
)
If non-NULL then types
creates a typed dictionary in which all
elements of the dictionary must inherit from these types
. Any class
can be given to types
as long as there is a valid as.character
method associated with the class.
add()
Add new items to the dictionary.
Dictionary$add(x = list(), keys = NULL, values = NULL)
x
(list()
)
Same as initialize, items to add to the list.
keys
(character()
)
If x
is NULL then keys
and values
can be provided to add the
new items by a character vector of keys and list of values instead.
values
(list()
)
If x
is NULL then keys
and values
can be provided to add the
new items by a list of keys and values instead.
remove()
Removes the given item from the list.
get()
Gets the given items from the dictionary. If only one item is requested then returns the (unlisted) item, or if multiple items are requested as the dictionary is typed, then the unlisted items are returned.
keys
(character()
)
Keys of items to get.
clone
(logical(1)
)
If TRUE
(default) then deep clones R6 objects if requested.
get_list()
Gets the given items from the dictionary as list.
keys
(character()
)
Keys of items to get.
clone
(logical(1)
)
If TRUE
(default) then deep clones R6 objects if requested.
assert_contains()
Asserts if the given keys are in the list, returns keys invisibly if assertion passes otherwise errors.
keys
(character()
)
Keys to check.
print()
Prints dictionary.
summary()
Summarises dictionary.
merge()
Merges another dictionary, or list of dictionaries, into self.