I am trying to execute as local job the following file, let's call it main.R:
# This is main.R
x <- 1
source("secondary.R")
The main point here is that I am sourcing another file (secondary.R) which relies on the existence of x like this:
# This is secondary.R
y <- x + 1
It seems like R Studio executes secondary.R in a new environment, as it seems to have no knowledge of x and the local job fails with this message:
Error in eval(ei, envir) : object 'x' not found
Calls: sourceWithProgress ... eval -> eval -> source -> withVisible -> eval -> eval
Execution halted
I have 2 questions at this point:
-
Is that a correct representation?
-
If yes, why is that the case and how to avoid this behavior?
Thanks