Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
sourceWithProgress() and nested R scripts #4586
Steps to reproduce the problem
Based on ropensci/drake#807, I predict that if we have a script called
x <- 1
and if we run the following
then the job launcher's environment will not have a binding for
Describe the problem in detail
It looks like
Describe the behavior you expected
The reason it creates a fresh environment is to support the "export results" features:
Because objects created by the script are placed in the fresh environment by default, that environment contains the "results" of the script which can be easily transferred back to the main session.
Do you export results from your scripts?
I believe the results were exported in ropensci/drake#807. @gadenbuie, is this true? Until I can access the local version of the job launcher, I cannot test this out myself. (I am having trouble compiling the IDE preview of 1.2.1335 because the Ubuntu 18 tarball appears to not have a
No, the results were not exported.
Briefly, here's the structure of the job I'm running:
I'm running the outer script as a job in RStudio, but the use of
@wlandau please correct me if I'm wrong, but by default drake tracks dependencies of the computation in the outer script by inspecting the environment in which the drake plan is created (or where
Technically, the computation succeeds as expected because evaluating
Here's a small example (also available in the reprex repo). We have a script called
inside_inner <- 1
And another script called
source("inner.R") inside_outer <- 2 cat(ls(), sep = "\n", file = "outer.out") cat(ls(envir = .GlobalEnv), sep = "\n", file = "global.out")
rstudioapi::jobRunScript("outer.R", workingDir = getwd(), exportEnv = NULL)
Yeilding the following results in
cat(readLines("outer.out"), sep = "\n") ## inside_outer
cat(readLines("global.out"), sep = "\n") ## emitProgress ## inside_inner ## sourceWithProgress
RStudio Version 1.2.1268 Build 1275 (87a9693)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.11.1 Chrome/65.0.3325.230 Safari/537.36
Edit: changed language to use outer/inner instead of primary/child throughout.