A function looks up free variables in the environment in which the function
was defined, not in the environment in which the function was called. The
latter is called something like 'dynamic scoping' and usually leads to trouble,
the former is 'lexical scoping' and leads to predictable results. Y
Hello,
See the help page for parent.frame, and use its argument to go back to
the frames of variables 'a' and 'b':
innerfunction<-function()
{
env1 <- parent.frame(1) # for 'b'
env2 <- parent.frame(2) # for 'a'
print(paste(env2$a, " from inner function"))
print(paste(env1$b,
2 matches
Mail list logo