Given a list or dataframe and an object to look for, the function looks for this object name within the data frame or across all levels of a list and returns it. In case the object is not found, nothing is returned (NULL)
Arguments
- myList
A dataframe, list or a nested list where to look for.
- toFind
A character string corresponding to the name of the object to find.
Examples
# create some silly containers where to look for:
## a data frame
df = data.frame(values = c(1:4),
identity = LETTERS[1:4],
other = c("pif", "paf", "pouf","pof"))
## a simple list
slist = list(values = c(1:20),
identity = LETTERS[1:4],
other = c("pif", "paf", "pouf","pof"))
## a nested list
nlist = list(
values = c(1:20),
other = c("pif", "paf", "pouf","pof"),
nested = list(
identity = LETTERS[1:4],
values2 = c(1:20),
other2 = c("pif", "paf", "pouf","pof")
))
## a more complicated nested list
nnlist = list(
values = c(1:20),
other = c("pif", "paf", "pouf","pof"),
nested = list(
nested2 = list(identity = LETTERS[1:4]),
values2 = c(1:20),
other2 = c("pif", "paf", "pouf","pof")
))
# looking for "identity" containers within each element
MoveR::listGet(df, "identity")
#> [1] "A" "B" "C" "D"
MoveR::listGet(slist, "identity")
#> [1] "A" "B" "C" "D"
MoveR::listGet(nlist, "identity")
#> [1] "A" "B" "C" "D"
MoveR::listGet(nnlist, "identity")
#> [1] "A" "B" "C" "D"