FlattenList: Flatten List

Description Usage Arguments Examples

View source: R/basic_functions.R

Description

flatten a nested list into a single list

Usage

1
FlattenList(li, rm.duplicated = TRUE, unname.li = TRUE, rm.empty = TRUE)

Arguments

li

list to flatten

rm.duplicated

logical, indicating whether or not to remove duplicated lists, Default: TRUE

unname.li

logical, indicating whether or not to unname lists, Default: TRUE

rm.empty

logical, indicating whether or not to remove empty lists, Default: TRUE

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
li <- list(LETTERS[1:3],
           list(letters[1:3],
                list(LETTERS[4:6])),
           DEF = letters[4:6],
           LETTERS[1:3],
           list() # Emtpy list
)
print(li)
# [[1]]
# [1] "A" "B" "C"
#
# [[2]]
# [[2]][[1]]
# [1] "a" "b" "c"
#
# [[2]][[2]]
# [[2]][[2]][[1]]
# [1] "D" "E" "F"
#
#
#
# $DEF
# [1] "d" "e" "f"
#
# [[4]]
# [1] "A" "B" "C"
#
# [[5]]
# list()
FlattenList(li)
# [[1]]
# [1] "A" "B" "C"
#
# [[2]]
# [1] "a" "b" "c"
#
# [[3]]
# [1] "D" "E" "F"
#
# [[4]]
# [1] "d" "e" "f"

bfw documentation built on Jan. 11, 2020, 9:29 a.m.