gen_list: List comprehensions

Description Usage Arguments Details Value Examples

View source: R/lst.R

Description

Create lists of elements using an expressive syntax. Internally nested for-loops are created and compiled that generate the list.

Usage

1
gen_list(element_expr, ..., .compile = TRUE, .env = parent.frame())

Arguments

element_expr

an expression that will be collected

...

either a logical expression that returns a length 1 result. A named list of equal length sequences that are iterated over in parallel or a named parameter with an iterable sequence.

.compile

compile the resulting for loop to bytecode befor eval

.env

the parent environment in which all the elements are being evaluated.

Details

For parallel iterations all elements in the list need to be of equal length. This is not checked at runtime at the moment.

Value

A list of all generated values. The element-type is determined by the parameter element_expr.

Examples

1
2
3
4
5
6
7
gen_list(c(x, y), x = 1:10, y = 1:10, x + y == 10, x < y)
z <- 10
gen_list(c(x, y), x = 1:10, y = 1:10, x + y == !!z, x < y)

# it is also possible to iterate in parallel by passing a list of
# sequences
gen_list(c(x, y), list(x = 1:10, y = 1:10), (x + y) %in% c(4, 6))

listcomp documentation built on Jan. 31, 2022, 5:07 p.m.