It can be useful to create an list with default values and some settable values. This is similar to the idea of seq_along(), which creates a vector of the same length as its input.

list_along(names, default = NA, some = NA)

Arguments

names

names of the list to be generated

default

default value for each element of the generated list

some

a list with elements whose names should be included in names, use this to set default values for some elements of the generated list

Value

a list

Examples

list_along(names = c("A", "B", "C"), default = NA, some = list(B = 1))
#> $A #> [1] NA #> #> $B #> [1] 1 #> #> $C #> [1] NA #>