scdrake_list | R Documentation |
scdrake
's list with overloaded, strict access operators.It behaves like a normal list, but, by default, it has more strict rules for non-existing elements:
$
, [
, and [[
operators are overloaded for this class.
They try to extract element(s) from a scdrake_list
object, but throw an error when the element(s) does not exist.
This behaviour can be avoided for [
and [[
by using the check = FALSE
parameter, e.g. l[name, check = FALSE]
.
Also, in that case and for [
, a scdrake_list
with non-existing names and NULL
values is returned instead of putting
NA_character_
for them, which is the default behaviour for a base list, e.g.
> list(a = 2)["b"] $<NA> NULL
compared to
> scdrake_list(list(a = 2))["b", check = FALSE] $b NULL attr(,"class") [1] "scdrake_list"
However, this does not work for numeric subscripts.
scdrake_list(l = NULL)
## S3 method for class 'scdrake_list'
x$i
## S3 method for class 'scdrake_list'
x[i, check = TRUE]
## S3 method for class 'scdrake_list'
x[[i, check = TRUE]]
l |
A list. |
x |
An object of class |
i |
A character scalar or vector: name / names of element(s) to extract. |
check |
A logical scalar: if |
An object of class scdrake_list
.
cfg <- scdrake_list(list(var_1 = 1, var_2 = 2))
# The standard list behavior.
cfg$var_1
cfg[["var_2"]]
cfg["var_1"]
cfg[c("var_1", "var_2")]
## Not run:
# Strict rules for non-existing elements - throws an error.
cfg$var_3
cfg[["var_3"]]
cfg[c("var_1", "var_3")]
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.