Dictionary {oeli} | R Documentation |
Dictionary R6 Object
Description
Provides a simple key-value interface based on R6.
Active bindings
keys
A
character
vector
of available keys.alias
A
list
of 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_name
A single
character
, the name for the key variable.alias_name
Optionally a single
character
, the name for the alias variable. Can also beNULL
(default) for no alias.value_names
A
character
(vector
), the names of the values connected to a key.value_assert
A
alist
with check functions for supplied values. For each element invalue_names
,values_assert
can have an identically named element of the formcheckmate::assert_*(...)
, where...
can be any arguments for the assertion function except for thex
argument.allow_overwrite
Either
TRUE
(default) to allow overwriting existing keys with new values, orFALSE
else. Duplicate keys are never allowed.keys_reserved
A
character
(vector
) of names that must not be used as keys.alias_choices
Optionally a
character
vector
of possible values for the alias. Can also beNULL
, then all alias values are allowed.dictionary_name
Optionally 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 acharacter
vector
),all the variables specified for
value_names
(if any, they must comply to thevalue_assert
checks).
Returns
invisibly the Dictionary
object
Method get()
getting elements
Usage
Dictionary$get(key, value = NULL)
Arguments
key
A single
character
, a value for the key variablekey_name
. Use the$keys
method for available keys.value
Optionally 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
key
A single
character
, a value for the key variablekey_name
. Use the$keys
method for available keys.
Returns
invisibly the Dictionary
object
Method print()
printing details of the dictionary
Usage
Dictionary$print()
Returns
invisibly the Dictionary
object