This function merges two or more lists to create a single, combined list. If two elements in different lists have the same name, items in the later list gain preference (e.g., if there are three lists, then values in the third list gain precedence over items with the same name in the second, and the second has precedence over items in the first).
Examples
list1 <- list(a=1:3, b='Hello world!', c=LETTERS[1:3])
list2 <- list(x=4, b='Goodbye world!', z=letters[1:2])
list3 <- list(x=44, b='What up, world?', z=c('_A_', '_Z_'), w = TRUE)
mergeLists(list1, list2)
#> $x
#> [1] 4
#>
#> $b
#> [1] "Goodbye world!"
#>
#> $z
#> [1] "a" "b"
#>
#> $a
#> [1] 1 2 3
#>
#> $c
#> [1] "A" "B" "C"
#>
mergeLists(list2, list1)
#> $a
#> [1] 1 2 3
#>
#> $b
#> [1] "Hello world!"
#>
#> $c
#> [1] "A" "B" "C"
#>
#> $x
#> [1] 4
#>
#> $z
#> [1] "a" "b"
#>
mergeLists(list1, list2, list3)
#> $x
#> [1] 44
#>
#> $b
#> [1] "What up, world?"
#>
#> $z
#> [1] "_A_" "_Z_"
#>
#> $w
#> [1] TRUE
#>
#> $a
#> [1] 1 2 3
#>
#> $c
#> [1] "A" "B" "C"
#>
mergeLists(list3, list2, list1)
#> $a
#> [1] 1 2 3
#>
#> $b
#> [1] "Hello world!"
#>
#> $c
#> [1] "A" "B" "C"
#>
#> $x
#> [1] 4
#>
#> $z
#> [1] "a" "b"
#>
#> $w
#> [1] TRUE
#>