Get Paths and String Values from Recursive List
Source:R/list.R
getPathsAndValuesFromRecursiveList.RdGet Paths and String Values from Recursive List
Value
data frame with columns path and value. The
data frame contains all non-list elements that are contained in x,
coerced to character, in column value, together with the sequence of
element names "leading" to the value when starting at x. For example,
the path to element x$a$a1 is /a/a1 (see example).
Examples
# Define a recursive list
x <- list(
a = list(a1 = "A1", a2 = "A2"),
b = list(b1 = "B1", b2 = "B2", b3 = "B3"),
c = list(c1 = list(c11 = "C11"), c2 = list(c21 = "C21", c22 = "C22"))
)
# Get all non-list-elements and their "path" as a data frame
getPathsAndValuesFromRecursiveList(x)
#> path value
#> 1 a/a1 A1
#> 2 a/a2 A2
#> 3 b/b1 B1
#> 4 b/b2 B2
#> 5 b/b3 B3
#> 6 c/c1/c11 C11
#> 7 c/c2/c21 C21
#> 8 c/c2/c22 C22