prepend_object: Prepending in a pipe, never unlisting

Description Usage Arguments Value Examples

View source: R/purrr-like.R

Description

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

Usage

1
prepend_object(x, .l, name = NULL, before = 1)

Arguments

x

Object to prepend. 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

before

Prepend before this index

Value

The list .l with x prepended

Examples

1
2
3
4
5
6
7
8
#' library(tibble)
library(magrittr)
library(dplyr)
results <- list(second=list(1,2), third=list(3))
list(-1, 1) %>%
  prepend_object(results, "first") ->
results
# results has length 3, containing three lists

tidytidbits documentation built on March 8, 2021, 5:07 p.m.