lst: Build a list

Description Usage Arguments Value Life cycle Examples

View source: R/lst.R

Description

\lifecycle

questioning

lst() constructs a list, similar to base::list(), but with some of the same features as tibble(). lst() builds components sequentially. When defining a component, you can refer to components created earlier in the call. lst() also generates missing names automatically.

Usage

1

Arguments

...

A set of name-value pairs. Arguments are evaluated sequentially, so you can refer to previously created elements. These arguments are processed with rlang::quos() and support unquote via !! and unquote-splice via !!!. Use := to create columns that start with a dot.

Value

A named list.

Life cycle

The lst() function is in the questioning stage. It is essentially rlang::list2(), but with a couple features copied from tibble(). It's not clear that a function for creating lists belongs in the tibble package. Consider using rlang::list2() instead.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# the value of n can be used immediately in the definition of x
lst(n = 5, x = runif(n))

# missing names are constructed from user's input
lst(1:3, z = letters[4:6], runif(3))

a <- 1:3
b <- letters[4:6]
lst(a, b)

# pre-formed quoted expressions can be used with lst() and then
# unquoted (with !!) or unquoted and spliced (with !!!)
n1 <- 2
n2 <- 3
n_stuff <- quote(n1 + n2)
x_stuff <- quote(seq_len(n))
lst(!!!list(n = n_stuff, x = x_stuff))
lst(n = !!n_stuff, x = !!x_stuff)
lst(n = 4, x = !!x_stuff)
lst(!!!list(n = 2, x = x_stuff))

krlmlr/tibble documentation built on Jan. 15, 2020, 7:56 a.m.