Skip to contents

Builds an environment containing the eml operator and the user-supplied bindings, then defers to base::eval. Vectorised inputs are supported transparently — if vars$x is length N, the result is length N.

Usage

eml_eval(expr, vars = list(), real = FALSE, tol = 1e-08)

Arguments

expr

an EML expression.

vars

named list of variable bindings, e.g. list(x = 2).

real

logical; if TRUE, return the real part with an imaginary-residue check.

tol

numeric tolerance for the residue check, or NA to skip.

Value

Complex (or numeric, if real = TRUE).

Details

By default the result is complex (the principal-branch domain of EML). Set real = TRUE to return Re(z), warning if the imaginary residue exceeds tol (the real part is still returned).

See also

compile_eml() / run_bytecode() for the vectorised stack-machine evaluator with the same semantics.

Examples

# exp(2)
eml_eval(quote(eml(x, 1)), list(x = 2), real = TRUE)
#> [1] 7.389056

# Vectorised: log evaluated at 30 points
xs <- seq(0.5, 5, length.out = 30)
lx <- eml_eval(quote(eml(1, eml(eml(1, x), 1))),
  list(x = xs),
  real = TRUE
)
max(abs(lx - log(xs)))
#> [1] 1.665335e-16