R/get_vectors_from_nested_list.R
get_vectors_from_nested_list.Rd
Return one or more values from a nested list in a list of vectors
get_vectors_from_nested_list(x, valuesIn = NULL, nestingIn = "children")
The nested list
The names holding the values to return (in vectors)
The name containing the nested lists
A list of vectors.
nestedList <-
list(
id = "x",
value = "value for x",
children = list(
list(
id = "y",
value = "value for y"
),
list(
id = "z",
value = "value for z"
)
)
);
str(nestedList);
#> List of 3
#> $ id : chr "x"
#> $ value : chr "value for x"
#> $ children:List of 2
#> ..$ :List of 2
#> .. ..$ id : chr "y"
#> .. ..$ value: chr "value for y"
#> ..$ :List of 2
#> .. ..$ id : chr "z"
#> .. ..$ value: chr "value for z"
get_vectors_from_nested_list(
nestedList,
c("id", "value")
);
#> [[1]]
#> id value
#> "x" "value for x"
#>
#> [[2]]
#> id value
#> "y" "value for y"
#>
#> [[3]]
#> id value
#> "z" "value for z"
#>