linearizeNestedList: linearize nested lists

Description Usage Arguments Value Author(s) References Examples

Description

This function un-nests a list and stores the result into a named list with all elements on the first depth level. The function is recursive and its input is only limited by the maximum nesting level R allows for.

Usage

1
2
  linearizeNestedList(nList, linearizeDataFrames = FALSE,
    nameSep = ".", forceNames = FALSE)

Arguments

nList

input nested List

linearizeDataFrames

logical to indicate whether data.frames should be linearized too

nameSep

character to seperate different list elements

forceNames

logical to indicate whether original names should be removed and sequential numbers should be used

Value

a linear list whose names hold the information containing in the nesting of the input list

Author(s)

Akhil Behl <akhilsbehl@gmail.com>, Matthias Bannert <bannert@kof.ethz.ch>

References

This function was originally created by Akhil Behl and was only slightly modified by the author of this package. The original code can be found on his website: https://sites.google.com/site/akhilsbehl/geekspace/articles/r/linearize_nested_lists_in_r

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# first create a nested list
nestedList <- list(A=list(a=c(1,2,3),b=c(3,2,1)),
                   B=list(a=c(4,5,6),
                   b=c(7,8,9),
                   d=list(a1="test",
                          b2="anther test")
                   ))

# call the linearize function for lists
linearList <- linearizeNestedList(nestedList)

# set the attribute "tskey" to to every list element based on its name
for.setattr(linearList)
linearList

mbannert/gateveys documentation built on May 21, 2019, 2:23 p.m.