tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,15 @@
|
|||
evalWithAB <- function(expr, var, a, b) {
|
||||
env <- new.env() # provide a separate env, so that the choosen
|
||||
assign(var, a, envir=env) # var name do not collide with symbols inside
|
||||
# this function (e.g. it could be even "env")
|
||||
atA <- eval(parse(text=expr), env)
|
||||
# and then evaluate the expression inside this
|
||||
# ad hoc env-ironment
|
||||
assign(var, b, envir=env)
|
||||
atB <- eval(parse(text=expr), env)
|
||||
return(atB - atA)
|
||||
}
|
||||
|
||||
print(evalWithAB("2*x+1", "x", 5, 3))
|
||||
print(evalWithAB("2*y+1", "y", 5, 3))
|
||||
print(evalWithAB("2*y+1", "x", 5, 3)) # error: object "y" not found
|
||||
Loading…
Add table
Add a link
Reference in a new issue