Skip to content
Prev 318420 / 398503 Next

sys.frame() and variables from parent frame

On Feb 27, 2013, at 1:11 AM, Z? Miguel wrote:

            
You can specify the global environment with either a function call or by a consant name

 globalenv()

 .GlobalEnv


In your code however, 'N' is not in the global environment and you are not passing a character argument to get() as you had been in your first example. Furthermore you have chosen to use write which does not gte the desired effect of reporting from inside a function.

g <- function()
{
get("N", envir = .GlobalEnv)  # character argument to get 
cat(N)
}

f<-function()
{
N<-99  # not in the global environment
g()
}

N <- 42  # assigned in the global environment
f()
# returns 42