Learn R Programming

purrr (version 0.3.4)

prepend: Prepend a vector

Description

This is a companion to append() to help merging two lists or atomic vectors. prepend() is a clearer semantic signal than c() that a vector is to be merged at the beginning of another, especially in a pipe chain.

Usage

prepend(x, values, before = NULL)

Value

A merged vector.

Arguments

x

the vector to be modified.

values

to be included in the modified vector.

before

a subscript, before which the values are to be appended. If NULL, values will be appended at the beginning even for x of length 0.

Examples

Run this code
x <- as.list(1:3)

x %>% append("a")
x %>% prepend("a")
x %>% prepend(list("a", "b"), before = 3)
prepend(list(), x)

Run the code above in your browser using DataLab