Storage | R Documentation |
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.
The output depends on the method:
$new()
returns a Storage
object.
$add()
, $remove()
, and $print()
invisibly return the
Storage
object (to allow for method chaining)
$get()
returns the requested element(s)
$number()
returns an integer
$indices()
return an integer
vector
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).
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.
identifier
[character()
]
The identifiers used.
confirm
[logical(1)
]
The default value for confirmations.
missing_identifier
[logical(1)
]
The default value for not specified identifiers.
hide_warnings
[logical(1)
]
Hide warnings (for example if unknown identifiers are selected)?
new()
Initializing a Storage
object.
Storage$new()
add()
Adding an element.
Storage$add( x, identifier, confirm = interactive() & self$confirm, missing_identifier = self$missing_identifier )
x
[any()
]
An object to be saved.
identifier
[character()
]
Pne or more identifiers (the identifier "all"
is reserved to select
all elements).
confirm
[logical(1)
]
Prompted for confirmation?
missing_identifier
[logical(1)
| NA]
The value for not specified identifiers.
get()
Getting elements.
Storage$get( identifier = character(), ids = integer(), logical = "and", confirm = interactive() & self$confirm, missing_identifier = self$missing_identifier, id_names = FALSE )
identifier
[character()
]
Pne or more identifiers (the identifier "all"
is reserved to select
all elements).
ids
[integer()
]
One or more ids.
logical
[character(1)
]
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
[logical(1)
]
Prompted for confirmation?
missing_identifier
[logical(1)
| NA]
The value for not specified identifiers.
id_names
[logical(1)
]
Name the elements according to their ids?
remove()
removing elements
Storage$remove( identifier = character(), ids = integer(), logical = "and", confirm = interactive() & self$confirm, missing_identifier = self$missing_identifier, shift_ids = TRUE )
identifier
[character()
]
Pne or more identifiers (the identifier "all"
is reserved to select
all elements).
ids
[integer()
]
One or more ids.
logical
[character(1)
]
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
[logical(1)
]
Prompted for confirmation?
missing_identifier
[logical(1)
| NA]
The value for not specified identifiers.
shift_ids
[logical(1)
]
Shift ids when in-between elements are removed?
number()
Computing the number of identified elements.
Storage$number( identifier = "all", missing_identifier = self$missing_identifier, logical = "and", confirm = FALSE )
identifier
[character()
]
Pne or more identifiers (the identifier "all"
is reserved to select
all elements).
missing_identifier
[logical(1)
| NA]
The value for not specified identifiers.
logical
[character(1)
]
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
[logical(1)
]
Prompted for confirmation?
indices()
Returning indices based on defined identifiers.
Storage$indices( identifier = "all", logical = "and", confirm = interactive() & self$confirm )
identifier
[character()
]
Pne or more identifiers (the identifier "all"
is reserved to select
all elements).
logical
[character(1)
]
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
[logical(1)
]
Prompted for confirmation?
print()
Printing details of the saved elements.
Storage$print(...)
...
Currently not used.
Other package helpers:
Dictionary
,
identical_structure()
,
input_check_response()
,
match_arg()
,
package_logo()
,
print_data.frame()
,
print_matrix()
,
renv_development_packages()
,
system_information()
,
unexpected_error()
,
user_confirm()
### 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.