select (and rename, if required) elements from list. Stop with message if elements do not exist
selectElements(x, elements = NULL, do.stop = TRUE, do.warn = TRUE)
x | list |
---|---|
elements | vector of element names. The names of named elements will be the names in the output list |
do.stop | this flag controls whether the function stops ( |
do.warn | if |
list containing the elements of x
that are specified in
elements
or x[[elements]]
if length of elements
is 1
or list()
if elements
is empty. If the elements in vector
elements
are named, these names are used in the output list.
L <- list(a = 1, b = 2, c = 3, d = 4) # Select elements selectElements(L, c("a", "c"))#> $a #> [1] 1 #> #> $c #> [1] 3 #># Select and rename at the same time selectElements(L, elements = c(a.new = "a", c.new = "c", "b"))#> $a.new #> [1] 1 #> #> $c.new #> [1] 3 #> #> $b #> [1] 2 #>