gen.list.expr: Generate List and Vector Expressions with List Comprehension

Description Usage Arguments Details Value See Also Examples

View source: R/gen-list.r

Description

Functions to transform a base expression containing free variables into a list or a vector of expressions, based on variable ranges and additional conditions.

Usage

1
2
3
4
5
6
7

Arguments

expr

A base expression which is partially evaluated for all combinations of variables. It may still contain free variables.

...

Arbitrary many variable ranges and conditions.

str

A character pattern, containing expressions to be evaluated in {}-brackets.

Details

See gen.list for more details on the expr and ... parameters.

See gen.named.list for more details on the str parameter.

For variables with underscores additionally the evaluation of indices in ()-brackets is supported. For example, an expression x_(i+1) is evaluated as x_3 for i = 2.

Value

Returns an expression containing a list or a vector which might be evaluated later. The argument expr is partially evaluated, where all free variables are substituted for which a range is given. The other variables remain untouched.

See Also

gen.list to generate lists, gen.named.list to generate named lists, and listcompr for an overview of all list comprehension functions.

Examples

1
2
3
4
5
6
7
8
# An expression which is partially evaluated
gen.list.expr(a_i + 2 * i, i = 1:4)

# Generate an expression with placeholders a_i,
# generate data for a_1, ..., a_4 and finally evaluate it
expr <- gen.vector.expr(a_i + a_(j+1), i = 1:3, j = 1:3, i != j)
data <- gen.data.frame(c(a_1 = a_1, ..., a_4 = a_4), a_ = 1:2)
eval(expr, data)

listcompr documentation built on June 10, 2021, 1:07 a.m.