Storage {oeli}R Documentation

Storage R6 Object

Description

Provides a simple indexing interface for list elements based on R6. Basically, it allows to store items in a list and to regain them based on identifiers defined by the user.

Value

The output depends on the method:

Setting identifiers

An identifier is a character, typically a binary property. Identifiers can be negated by placing an exclamation mark ("!") in front of them. Identifiers that have been assigned to other elements previously do not need to be specified again for new elements; instead, a default value can be used. This default value can be defined either globally for all cases (via the $missing_identifier field) or separately for each specific case (via the method argument).

User confirmation

If desired, the user can be asked for confirmation when adding, extracting, or removing elements using identifiers. This behavior can be set globally through the $confirm field or customized separately for each specific case via the method argument.

Active bindings

identifier

a character vector, the identifiers used

confirm

setting the default value for confirmations (either TRUE or FALSE)

missing_identifier

setting the default value for not specified identifiers (either TRUE, FALSE, or NA)

hide_warnings

either TRUE to hide warnings (for example if unknown identifiers are selected) or FALSE (default), else

Methods

Public methods


Method new()

initializing a Storage object

Usage
Storage$new()
Returns

a new Storage object


Method add()

adding an element

Usage
Storage$add(
  x,
  identifier,
  confirm = interactive() & self$confirm,
  missing_identifier = self$missing_identifier
)
Arguments
x

any object to be saved

identifier

a character vector with one or more identifiers (the identifier "all" is reserved to select all elements)

confirm

either TRUE to be prompted for confirmation, or FALSE else

missing_identifier

the logical value for not specified identifiers (either NA, TRUE, or FALSE)

Returns

invisibly the Storage object


Method get()

getting elements

Usage
Storage$get(
  identifier = character(),
  ids = integer(),
  logical = "and",
  confirm = interactive() & self$confirm,
  missing_identifier = self$missing_identifier,
  id_names = FALSE
)
Arguments
identifier

a character vector with one or more identifiers (the identifier "all" is reserved to select all elements)

ids

an integer vector of one or more ids

logical

in the case that multiple identifiers are selected, how should they be combined? options are:

  • "and" (the default): the identifiers are combined with logical and (all identifiers must be true)

  • "or": the identifiers are combined with logical or (at least one identifier must be true)

confirm

either TRUE to be prompted for confirmation, or FALSE else

missing_identifier

the logical value for not specified identifiers (either NA, TRUE, or FALSE)

id_names

either TRUE to name the elements according to their ids or FALSE if not

Returns

the selected object(s)


Method remove()

removing elements

Usage
Storage$remove(
  identifier = character(),
  ids = integer(),
  logical = "and",
  confirm = interactive() & self$confirm,
  missing_identifier = self$missing_identifier,
  shift_ids = TRUE
)
Arguments
identifier

a character vector with one or more identifiers (the identifier "all" is reserved to select all elements)

ids

an integer vector of one or more ids

logical

in the case that multiple identifiers are selected, how should they be combined? options are:

  • "and" (the default): the identifiers are combined with logical and (all identifiers must be true)

  • "or": the identifiers are combined with logical or (at least one identifier must be true)

confirm

either TRUE to be prompted for confirmation, or FALSE else

missing_identifier

the logical value for not specified identifiers (either NA, TRUE, or FALSE)

shift_ids

either TRUE to shift ids when in-between elements are removed, or TRUE to keep the ids

Returns

invisibly the Storage object


Method number()

computing the number of identified elements

Usage
Storage$number(
  identifier = "all",
  missing_identifier = self$missing_identifier,
  logical = "and",
  confirm = FALSE
)
Arguments
identifier

a character vector with one or more identifiers (the identifier "all" is reserved to select all elements)

missing_identifier

the logical value for not specified identifiers (either NA, TRUE, or FALSE)

logical

in the case that multiple identifiers are selected, how should they be combined? options are:

  • "and" (the default): the identifiers are combined with logical and (all identifiers must be true)

  • "or": the identifiers are combined with logical or (at least one identifier must be true)

confirm

either TRUE to be prompted for confirmation, or FALSE else

Returns

an integer


Method indices()

returning indices based on defined identifiers

Usage
Storage$indices(
  identifier = "all",
  logical = "and",
  confirm = interactive() & self$confirm
)
Arguments
identifier

a character vector with one or more identifiers (the identifier "all" is reserved to select all elements)

logical

in the case that multiple identifiers are selected, how should they be combined? options are:

  • "and" (the default): the identifiers are combined with logical and (all identifiers must be true)

  • "or": the identifiers are combined with logical or (at least one identifier must be true)

confirm

either TRUE to be prompted for confirmation, or FALSE else

Returns

an integer vector


Method print()

printing details of the saved elements

Usage
Storage$print(...)
Arguments
...

currently not used

Returns

invisibly the Storage object

Examples

### 1. Create a `Storage` object:
my_storage <- Storage$new()

# 2. Add elements along with identifiers:
my_storage$
  add(42, c("number", "rational"))$
  add(pi, c("number", "!rational"))$
  add("fear of black cats", c("text", "!rational"))$
  add("wearing a seat belt", c("text", "rational"))$
  add(mean, "function")

# 3. What elements are stored?
print(my_storage)

# 4. Extract elements based on identifiers:
my_storage$get("rational")
my_storage$get("!rational")
my_storage$get(c("text", "!rational"))
my_storage$get("all") # get all elements
my_storage$get(c("text", "!text"))
my_storage$get(c("text", "!text"), logical = "or")

# 5. Extract elements based on ids:
my_storage$get(ids = 4:5)
my_storage$get(ids = 4:5, id_names = TRUE) # add the ids as names

[Package oeli version 0.5.2 Index]