append_object: Appending in a pipe, never unlisting

View source: R/purrr-like.R

append_objectR Documentation

Appending in a pipe, never unlisting

Description

Append to a given list, while considering as a single object and not unlisting as base::append does. Argument order is reversed compared to base::append to allow a different pattern of use in a pipe.

Usage

append_object(x, .l, name = NULL)

Arguments

x

Object to append. If the object is a list, then it is appended as-is, and not unlisted.

.l

The list to append to. Special case handling applies if .l does not exist: then an empty list is used. This alleviates the need for an initial mylist <- list()

name

Will be used as name of the object in the list

Value

The list .l with x appended

Examples

library(magrittr)
results <- list(first=c(3,4), second=list(5,6))
list(7,8) %>%
  append_object(results, "third result") ->
results
# results has length 1, containing one list named "first"

tidytidbits documentation built on March 18, 2022, 6:10 p.m.