listcompr (version 0.1.0)

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

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

gen.list.expr(expr, ...)

gen.vector.expr(expr, ...)

gen.named.list.expr(str, expr, ...)

gen.named.vector.expr(str, expr, ...)

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.

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.

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.

See Also

gen.data.frame to generate data frames, gen.list to generate lists, gen.list.char to generate lists of characters, and listcompr for an overview of all list comprehension functions.

Examples

Run this code
# NOT RUN {
# 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)

# }

Run the code above in your browser using DataLab