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. Non-standard evaluation possible.

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 ) )
#> Error in add_to_list(add_to_list(list(), "A", 1:3), "B", list(C = 1, D = 2)): object 'y' not found
print(l)
#> Error in eval(expr, envir, enclos): object 'l' not found