Eval {lazy.symbolic}R Documentation

Evaluate Symbolic Expression Which Consists of Numbers

Description

Evaluate Symbolic Expression Which Consists of Numbers

Usage

Eval(exp, ..., values = NULL, check = 1, ntogoback = 2, debug = 0)

Arguments

exp

Symbolic expression

...

Replacement of the form pat1=pat2

values

A character vector consisting of several replacements separated by semicolons.

check

= 0 not to check if the expression is evaluatable. (See below.)

ntogoback

n parameter of sys.parent function

debug

debug parameter for matReplace

Details

This function first replaces the elements of pat1 matrix included in exp with the corresponding elements of pat2 matrix.
Then, if the resulting expression contains numbers only, it evaluates the result.

See the description of matReplace function for details.

This function does NOT attempt to evaluate the expression if the result of the replacement has any alphabets.
Therefore, if the expression has a function call, with check=1, it will not be evaluated.
Use check=0 if you are sure that the resulting expression is valid.

Value

A numeric matrix of the same size as exp

Examples


# matrix replacement
A <- demomat(2,2, root="a")
B <- demomat(2,2, root="b")
An <- demomat(2,2)
Bn <- demomat(2,2)*1000
ApB <- Plus(A,B)
ApBn <- Eval(ApB, A=An, B=Bn)
ApBn2 <- Eval(ApB, values=c("A=An; B=Bn") )
Print(ApB, ApBn, An+Bn)
Print(ApBn, ApBn2)

AtB <- matTimes(A,B)
AtBn <- Eval(AtB, A=An, B=Bn)
Print(AtB, AtBn, An%*%Bn)

# scalar replacement
val <- "a=1; b=2; c=3; d=4; e=5"
exp <- "(a+b*c-d)/e"
Eval(exp,values=val)

# Below causes an error.
# Eval(A)


[Package lazy.symbolic version 0.1.3 Index]