Skip to content
Back to formatted view

Raw Message

Message-ID: <503601C4.1050008@yahoo.de>
Date: 2012-08-23T10:11:16Z
From: Jannis
Subject: strange behaviour when sourcing inside function
In-Reply-To: <8D2E5359-D699-46AF-8FBA-8374FB3C7544@gmail.com>

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.
>