| Dictionary {oeli} | R Documentation |
Dictionary R6 Object
Description
Provides a simple key-value interface based on R6.
Active bindings
keysA
charactervectorof available keys.aliasA
listof available keys per alias value.
Methods
Public methods
Method new()
initializing a Dictionary object
Usage
Dictionary$new( key_name, alias_name = NULL, value_names = character(), value_assert = alist(), allow_overwrite = TRUE, keys_reserved = character(), alias_choices = NULL, dictionary_name = NULL )
Arguments
key_nameA single
character, the name for the key variable.alias_nameOptionally a single
character, the name for the alias variable. Can also beNULL(default) for no alias.value_namesA
character(vector), the names of the values connected to a key.value_assertA
alistwith check functions for supplied values. For each element invalue_names,values_assertcan have an identically named element of the formcheckmate::assert_*(...), where...can be any arguments for the assertion function except for thexargument.allow_overwriteEither
TRUE(default) to allow overwriting existing keys with new values, orFALSEelse. Duplicate keys are never allowed.keys_reservedA
character(vector) of names that must not be used as keys.alias_choicesOptionally a
charactervectorof possible values for the alias. Can also beNULL, then all alias values are allowed.dictionary_nameOptionally a single
character, a name for the dictionary.
Returns
a new Dictionary object
Method add()
adding an element
Usage
Dictionary$add(...)
Arguments
...Values for
the key variable
key_name(must be a singlecharacter),the alias variable
alias_name(optionally, must then be acharactervector),all the variables specified for
value_names(if any, they must comply to thevalue_assertchecks).
Returns
invisibly the Dictionary object
Method get()
getting elements
Usage
Dictionary$get(key, value = NULL)
Arguments
keyA single
character, a value for the key variablekey_name. Use the$keysmethod for available keys.valueOptionally a single
character, one of the elements invalue_names, selecting the required value. Can also beNULL(default) for all values connected to thekey, returned as alist.
Returns
the selected value
Method remove()
removing elements (and associated alias, if any)
Usage
Dictionary$remove(key)
Arguments
keyA single
character, a value for the key variablekey_name. Use the$keysmethod for available keys.
Returns
invisibly the Dictionary object
Method print()
printing details of the dictionary
Usage
Dictionary$print()
Returns
invisibly the Dictionary object