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.
lst(...)
... | A set of name-value pairs. Arguments are evaluated sequentially,
so you can refer to previously created elements. These arguments are
processed with |
---|
A named list.
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.
#> $n #> [1] 5 #> #> $x #> [1] 0.3608737 0.6525100 0.1435592 0.6807986 0.8592859 #>#> $`1:3` #> [1] 1 2 3 #> #> $z #> [1] "d" "e" "f" #> #> $`runif(3)` #> [1] 0.8386300 0.8813129 0.2376977 #>a <- 1:3 b <- letters[4:6] lst(a, b)#> $a #> [1] 1 2 3 #> #> $b #> [1] "d" "e" "f" #># 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))#> $n #> [1] 5 #> #> $x #> [1] 1 2 3 4 5 #>lst(n = !!n_stuff, x = !!x_stuff)#> $n #> [1] 5 #> #> $x #> [1] 1 2 3 4 5 #>lst(n = 4, x = !!x_stuff)#> $n #> [1] 4 #> #> $x #> [1] 1 2 3 4 #>#> $n #> [1] 2 #> #> $x #> [1] 1 2 #>