Provides a simple key-value interface based on R6.
keys
A character
vector
of available keys.
alias
A list
of available keys per alias value.
new()
initializing a Dictionary
object
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
)
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 be NULL
(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
in value_names
, values_assert
can have an identically named
element of the form checkmate::assert_*(...)
, where ...
can be
any arguments for the assertion function except for the x
argument.
allow_overwrite
Either TRUE
(default) to allow overwriting existing keys with new
values, or FALSE
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 be NULL
, then all alias values are allowed.
dictionary_name
Optionally a single character
, a name for the dictionary.
a new Dictionary
object
add()
adding an element
Dictionary$add(...)
...
Values for
the key variable key_name
(must be a single character
),
the alias variable alias_name
(optionally, must then be a
character
vector
),
all the variables specified for value_names
(if any, they must
comply to the value_assert
checks).
invisibly the Dictionary
object
key
A single character
, a value for the key variable key_name
.
Use the $keys
method for available keys.
value
Optionally a single character
, one of the elements in
value_names
, selecting the required value.
Can also be NULL
(default) for all values connected to the
key
, returned as a list
.
the selected value
key
A single character
, a value for the key variable key_name
.
Use the $keys
method for available keys.
invisibly the Dictionary
object
invisibly the Dictionary
object