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 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.

Returns

a new Dictionary object


Method add()

adding an element

Usage
Dictionary$add(...)
Arguments
...

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).

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 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.

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 variable key_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


[Package oeli version 0.5.2 Index]