Skip to contents

build_function(exprs, ...) returns an R function whose arguments are the groups in ...: each group is a list of variables (passed as one numeric vector) or a single variable (passed as a number). Observed equations, if given, are computed first, so exprs may refer to observed variables. This plays the role of Symbolics' build_function.

Usage

build_function(exprs, ..., observed = list(), cse = TRUE, expression = FALSE)

Arguments

exprs

An expression, a list of expressions, or a list matrix.

...

Argument groups. Named arguments name the function arguments; unnamed ones are called u, p and t in order, or a1, a2, ...

observed

Observed equations to compute first.

cse

Use common subexpression elimination.

expression

Return the function's R code instead of the function.

Value

An R function, or a language object when expression = TRUE.

Examples

x <- Symbol("x"); y <- Symbol("y"); a <- Symbol("a")
f <- build_function(list(x * a, sin(y)), list(x, y), a)
f(c(1, 2), 3)
#> [1] 3.0000000 0.9092974