flatten: Flatten list

Description Usage Arguments Details Value Examples

View source: R/flatten.R

Description

Flatten a (nested) list to a list of its leaves

Usage

1
flatten(x, flatten.df = FALSE, keep.order = TRUE)

Arguments

x

a list object

flatten.df

should data.frames also be flattened?

keep.order

keep the order of the original list, same as seen when using str

Details

The nodes of the supplied list is traversed from root to leaf and successively unlisted until no lists are left (except possibly for data.frames).

Value

A single level list of x's leaves.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
xl <- list(
  O=NA, 
  R=list(
    j=1:3,
    h="(a)",
    q=data.frame(
      a=1:2, 
      b=c("A, K", "B, L"),
      stringsAsFactors=FALSE
    )
  ), 
  N=1,
  L=FALSE
)

flatten(xl, flatten.df=TRUE, keep.order=FALSE)
flatten(xl, flatten.df=TRUE, keep.order=TRUE)
str(xl)

AkselA/R-ymse documentation built on March 21, 2020, 9:52 a.m.