The code consists in two files:
caller.R
:
a <- 1
source("s1.R", encoding = "UTF-8")
b <- fa()
s1.R
:
fa <- function() {
a*2
}
This code runs smoothly when caller.R
is sourced (Crtl Shift S) in RStudio IDE, providing the correct expected result b=2
.
However, when caller.R
is sourced through "Source as Local Job...", it throws an error (Portuguese), meaning that execution was interrupted because it was not able to find object 'a':
Error in fa() : objeto 'a' n�o encontrado
Calls: sourceWithProgress -> eval -> eval -> fa
Execu��o interrompida
I have tried all possible "Source as Local Job..." options combinations ("Run job with copy of global environments, etc.) without success.
What do I have to do to be able to run caller.R as a local job?
CodePudding user response:
If you want to have it available in the same environment, you can try to use the local = TRUE
source("s1.R", encoding = "UTF-8", local = TRUE)