Hello:

I'm writing code to modify a function, and I want to know how to access the executing environment of the function. The example below extracts the body of a function and executes a single line but can't find "x1" in the function's executing environment. How would you suggest fixing this? Thanks, Spencer


fun1 <- function(x1=1){
  y <- x1
}
fun2 <- function(fun=fun1){
  bo <- body(fun)
  bo2 <- bo[[2]]
  z <- eval(bo2)
}
tst <- fun2()

Error in eval(expr, envir, enclos) : object 'x1' not found


______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to