[R] strange behaviour when sourcing inside function

Noia Raindrops noia.raindrops at gmail.com
Wed Aug 22 21:25:14 CEST 2012


Hello,

If argument 'local' is FALSE, 'source' function is evaluating the file in global environment
and object 'a' is not in global environment.

Function's environment is just local. And environment() in a function returns the function's environment.


test <- function () source("test.R", local = FALSE)
# test.R is evaluated in global environment.

test <- function () source("test.R", local = environment())
# environment() returns the envrionment of 'test' function.

test <- function () source("test.R", local = TRUE)
# this is same as above.

-- 
Noia Raindrops
noia.raindrops at gmail.com




More information about the R-help mailing list