Bug: MOFA2 sets an environment variable that breaks knit in RStudio
Entering edit mode
Kevin Coombes ▴ 430
Last seen 20 months ago
United States

I ran into a problem using MOFA2 inside an R console session and then trying to knit an Rmarkdown script. Specifically, whenever I try to knit anything within RStudio after calling "run_mofa", the knit fails at the first point that it encounters any function in one of the standard default packages (stats, utils, etc.). I filed a bug report with RStudio. Working with someone there, we found that the call to run_mofa causes a new environmental variable to be set:


This variable is not set when I start an R session, nor is set after simply loading the library package. It only exists after calling "run_mofa". It persists in the separate R sessions started when invoking "knit" from the button in RStudio. This value of the variable prevents loading of the standard packages.

I would (strongly) suggest unsetting or restoring any global environment variables that were changed within the scope of the function before exiting the function. At the very least, this phenomenon should be documented somewhere in case other people run into the same problem.

RStudio MOFA2 bug knitr • 890 views
Entering edit mode
Last seen 7 days ago
United States

This isn't an issue with MOFA2, but instead is due to something basilisk does when setting up an env.

> library(basilisk)
> Sys.getenv("R_DEFAULT_PACKAGES")
[1] ""

## run some example code
> tmploc <- file.path(tempdir(), "my_package_B")
>      if (!file.exists(tmploc)) {
          setupBasiliskEnv(tmploc, c('pandas=0.25.1',
              "python-dateutil=2.8.0", "pytz=2019.3"))


> cl <- basiliskStart(tmploc)
> Sys.getenv("R_DEFAULT_PACKAGES")
[1] "NULL"

This occurs as part of basilisk.utils:::activateEnvironment, which to be clear does give the option of outputting the adjusted variables so you could hypothetically use basilisk.utils:::deactivateEnvironment to reset.

> basilisk.utils:::deactivateEnvironment(list(R_DEFAULT_PACKAGES = ""))
> Sys.getenv("R_DEFAULT_PACKAGES")
[1] ""

Unfortunately basiliskStart doesn't save those values, so it's not possible at the moment to do anything about it. Other than restarting R that is - the variable isn't persistent so I don't know what you mean by 'It persists in the separate R sessions started when invoking "knit" from the button in RStudio.' When I restart R, it's no longer there.

I suppose basiliskStop should be in charge of resetting those values (and it does get called at the end of run_mofa), but you will need to make another post with 'basilisk' as a tag to get Aaron Lun's attention, since basilisk is his package.


Login before adding your answer.

Traffic: 801 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6