lappend: Append individual values to a list

View source: R/lappend.R

lappendR Documentation

Append individual values to a list

Description

If passed two lists, the standard append() function will concatenate the lists, rather than treating the second list as a value that should be appended to the list. In contrast, the lappend() function will always append individual values to a list (it does this by making sure that each element is encapsulated in its own list before using base::append() to put it in the original list).

Importantly, this approach correctly allows adding a data.frame to a list, whereas calling base::append() directly will add each column as a separate element.

Usage

lappend(l, ..., .after = length(l))

Arguments

l

The list to append to.

...

One or more values to be appended to the list, each as a separate list element.

.after

At what position to append.

Value

A list with the specified values appended at the correct position.

Examples

l <- list()
l <- append(l, cars)
l <- append(l, mtcars)
length(l) # l is a list of 13 vectors

l <- list()
l <- lappend(l, cars)
l <- lappend(l, mtcars)
length(l) # l is a list of 2 data.frames


torfason/zulutils documentation built on Aug. 21, 2023, 5:46 p.m.