russHyde / code_as_data

Analysis of code in R dev packages (for a planned talk)
9 stars 0 forks source link

Convert to renv #31

Closed russHyde closed 3 years ago

russHyde commented 3 years ago

fixes #29

Initially had a conda environment (plus some install_githubs)

Had trouble updating the env: both slowness of solving env, and impossibility
of installing some packages (pkgnet)

The initial env was based on R-3.5 and had rstudio inside it

So it was a reluctant beast

Also needed to have a separate ./setup script to ensure that github packages
were installed correctly, once the conda-env was in place.

Recommendation

TODO:

russHyde commented 3 years ago

Attempt to get nextflow pipeline to run with renv was a failure.

Since nextflow processes run in a temp directory, they don't necessarily have access to files that are implicitly required.

Here,

So, we need a way to copy / link implicit file-dependencies into the working directory for any process that runs an R script; but I can't find a good explanation for how to do that within nextflow.

ekatsevi commented 1 year ago

I think I resolved this issue. All you need for an R script to use the renv packages is to have the R_LIBS_USER environment variable pointing to the underlying R library path. You can get this path in R by activating the renv and then typing cat(paste0(.libPaths(), collapse = ":")). According to the Nextflow documentation on configuration, "The env scope allows the definition one or more variable that will be exported in the environment where the workflow tasks will be executed." Therefore, if your Nextflow configuration file contains the line env.R_LIBS_USER = /path/to/renv/libs, then each process will have access to your renv libraries. You can even carry out the above steps programmatically in a bash script as follows:

RENV_R_LIBS_USER=$(Rscript -e '
renv::activate(); 
cat(paste0(.libPaths(), collapse = ":"))')
echo "env.R_LIBS_USER = \"$RENV_R_LIBS_USER\"" > nextflow.config

Hope this helps!

russHyde commented 1 year ago

Amazing. I'd recently started looking back at this project (though I don't use nextflow for work nowadays). Thanks for posting your solution.