Flattens All List Levels Using Separated Names

unlist_with_sep(x, sep = "/", use.names = TRUE, depth = Inf)

Arguments

x

a list object, usually containing other lists -- of lists.

sep

character string used to separate each component of the final element names.

use.names

logical that indicates if the original names of each the sucessive nested list elements should be used to build the final names of the result list.

depth

maximum number of levels to unlist. Root level is 1L.

Examples

x <- list(X = list(a = 1 , b = list(b.1 = 2 , b.2 = list(b.2.1 = 4, b.2.2 = data.frame()) , b.3 = 3) , c = matrix())) unlist_with_sep(x)
#> $`X/a` #> [1] 1 #> #> $`X/b/b.1` #> [1] 2 #> #> $`X/b/b.2/b.2.1` #> [1] 4 #> #> $`X/b/b.2/b.2.2` #> data frame with 0 columns and 0 rows #> #> $`X/b/b.3` #> [1] 3 #> #> $`X/c` #> [,1] #> [1,] NA #>
unlist_with_sep(x, '###')
#> $`X###a` #> [1] 1 #> #> $`X###b###b.1` #> [1] 2 #> #> $`X###b###b.2###b.2.1` #> [1] 4 #> #> $`X###b###b.2###b.2.2` #> data frame with 0 columns and 0 rows #> #> $`X###b###b.3` #> [1] 3 #> #> $`X###c` #> [,1] #> [1,] NA #>