New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sourceWithProgress() and nested R scripts #4586
Comments
|
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 <- 1And 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")Running rstudioapi::jobRunScript("outer.R", workingDir = getwd(), exportEnv = NULL)Yeilding the following results in cat(readLines("outer.out"), sep = "\n")
## inside_outerNotice that cat(readLines("global.out"), sep = "\n")
## emitProgress
## inside_inner
## sourceWithProgresssession_info()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. |
|
Thanks @gadenbuie.
By default, |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions. |
|
This issue has been automatically closed due to inactivity. |

System details
Steps to reproduce the problem
Based on ropensci/drake#807, I predict that if we have a script called
inner.Rand if we run the following
job.Rscript in the job launchersource("inner.R")then the job launcher's environment will not have a binding for
x. @gadenbuie, would you mind verifying this (and filling in your system details above)? I do not have access to the job launcher myself.Describe the problem in detail
It looks like
sourceWithProgress()creates a fresh clean environment in which to source the R script, which seems like a good idea. However, what if the script itself sources other scripts? By default, the child scripts will use the global environment, not the environment that sources the parent script: https://stackoverflow.com/questions/55008645/control-the-environment-of-nested-calls-to-source. I believe this might be affecting ropensci/drake#807 and https://github.com/gadenbuie/drake-rstudio-jobs-example#readme.Describe the behavior you expected
I expect/hope
xto be defined in the environment in which the job launcher runsjob.R.The text was updated successfully, but these errors were encountered: