expand_list: Easy way to add an empty list to a list

Description Usage Arguments Details Examples

View source: R/expand_list.R

Description

Add an empty list to a list at a position specified by a character vector, which is interpreted recursively. See Examples.

Usage

1
expand_list(.list, position)

Arguments

.list

A list.

position

A character vector.

Details

'[[' allows indexing a list with a vector, but only if the indices are already present in the list. expand_list implements an easy way to equip a list with the needed indices.

Examples

1
2
3
4
5
6
7
l <- list()
# Add empty list "a" on top level
l <- expand_list(l, "a")
# Add list "b" on top level with empty list "c" inside it
l <- expand_list(l, c("b", "c"))
# Add empty list "d" to the previously defined list "b"
l <- expand_list(l, c("b", "d"))

DavidBarke/QWUtils documentation built on Jan. 13, 2020, 11:52 a.m.