[R] how to access an executing environment?
Spencer Graves
spencer.graves at structuremonitoring.com
Thu May 29 02:29:04 CEST 2014
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
>
More information about the R-help
mailing list