as_func {caracas}R Documentation

Convert expression into function object.

Description

Convert expression into function object.

Usage

as_func(x, order = NULL, vec_arg = FALSE)

## S3 method for class 'caracas_symbol'
as.function(x, ...)

Arguments

x

caracas expression.

order

desired order of function argument. Defaults to alphabetical ordering.

vec_arg

should the function take vector valued argument.

...

not used

Examples

if (has_sympy()) {
  def_sym(b0, b1, b2, k, x)
  e <- b1 + (b0 - b1)*exp(-k*x) + b2*x

  f1 <- as_func(e)
  f1
  f1(1, 2, 3, 4, 5)
  f1 <- as_func(e, order = sort(all_vars(e)))
  f1(1, 2, 3, 4, 5)
  f2 <- as_func(e, vec_arg = TRUE)
  f2
  f2(c(1, 2, 3, 4, 5))
  f2 <- as_func(e, order = sort(all_vars(e)), vec_arg = TRUE)
  f2
  f2(c(1,2,3,4,5))
  
  f1a <- as.function(e)
  f1a
  f1a(1, 2, 3, 4, 5)
  f1(1, 2, 3, 4, 5)
}

[Package caracas version 2.1.1 Index]