[R] strange behaviour when sourcing inside function

Jannis bt_jannis at yahoo.de
Thu Aug 23 12:11:16 CEST 2012


Thanks for your reply! You may be correct, but the documentation of 
"source" reads as whether the opposite is the case regarding the use of 
TRUE and FALSE, doesn't it?

Your interpretation may be correct (it would be also in line with my 
inutive interpretation of the combination of the word local and the 
corresponding boolean values) but if it is, the manual (to me) is 
misleading.


Cheers
Jannis

On 22.08.2012 21:25, Noia Raindrops wrote:
> 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.
>




More information about the R-help mailing list