Re: [R] Functions within functions - environments

2013-06-12 Thread William Dunlap
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

Re: [R] Functions within functions - environments

2013-06-12 Thread Rui Barradas
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,