calculus (version 0.1.0)

evaluate: Numerical Evaluation

Description

Evaluate an array of characters, expressions or functions.

Usage

evaluate(x, envir = parent.frame(), enclos = if (is.list(envir) ||
  is.pairlist(envir)) parent.frame() else baseenv(), simplify = TRUE)

Arguments

x

an object to be evaluated: array of characters, expressions or functions.

envir

the environment in which x is to be evaluated. May also be NULL, a list, a data frame, a pairlist or an integer as specified to sys.call.

enclos

relevant when envir is a (pair)list or a data frame. Specifies the enclosure, i.e., where R looks for objects not found in envir. This can be NULL (interpreted as the base package environment, baseenv()) or an environment.

simplify

logical. Simplify the output? If FALSE, return a list.

Value

evaluated object.

Examples

Run this code
# NOT RUN {
##################################
# Evaluate an array of characters
#

x <- array(letters[1:4], dim = c(2,2))

e <- list(a = 1, b = 2, c = 3, d = 4)
evaluate(x, env = e)
evaluate(x, env = e, simplify = FALSE)

e <- list(a = 1:3, b = 2, c = 3, d = 4)
evaluate(x, env = e)
evaluate(x, env = e, simplify = FALSE)


##################################
# Evaluate an array of functions
#

f1 <- function(x,y) sin(x)
f2 <- function(x,y) sin(y)
f3 <- function(x,y) x*y
x <- array(c(f1,f3,f3,f2), dim = c(2,2))

e <- list(x = 0, y = pi/2)
evaluate(x, env = e)
evaluate(x, env = e, simplify = FALSE)

e <- list(x = c(0, pi/2), y = c(0, pi/2))
evaluate(x, env = e)
evaluate(x, env = e, simplify = FALSE)
  
# }

Run the code above in your browser using DataLab