A function that adds a new element to a pre-existing list. Allows greater compatibility with the pipe operator.

add_to_list(l, name, e)

Arguments

l

A list.

name

A character string, the name of the new element being added.

e

An R object, the new element to add to the list.

Value

A list with an additional element e

with the specified name.

Examples

l <- list() |>
  add_to_list( 'A', 1:3 ) |>
  add_to_list( 'B', list( C = 1, D = 2 ) )
print(l)
#> $A
#> [1] 1 2 3
#> 
#> $B
#> $B$C
#> [1] 1
#> 
#> $B$D
#> [1] 2
#> 
#>