My HPC runs CentOS while the container is running Ubuntu Focal. This means that when packages link a system dependency, that system dependency might be in different places. So, I can't use the same built binaries for some packages because they'll break when a system dependency they need isn't where it is expected (this happens when a package is built in one OS but loaded in the other).
To fix this I need to keep the CentOS and Ubuntu libraries separate from each other. This is simple enough when not using renv
, but I'm looking for reproducibility, so I need an renv
compatible way to keep the libraries separate.
To do this I define an Renviron.site
file that will be used by the container that sets an environmental variables for a prefix for the renv
cache and the project library. Then I bind mount the Renviron.site
file in the container and renv
picks up the environmental variable and keeps things separate.
Here's the relevant portion of the Renviron.site
file:
RENV_PATHS_PREFIX=rocker
Now when I'm working in the container renv
uses ~/.cache/R/renv/cache/v5/rocker/R-4.1/x86_64-pc-linux-gnu
for the cache instead of ~/.cache/R/renv/cache/v5/R-4.1/x86_64-pc-linux-gnu
and renv/library/rocker/R-4.1/x86_64-pc-linux-gnu
for the project library instead of renv/library/R-4.1/x86_64-pc-linux-gnu
. If I'm working directly in the HPC (including submitting jobs), renv
uses the latter set of paths so the CentOS versions of the packages are loaded.
When running singularity exec
I add this option to bind mount the Renviron.site
file into the container:
--bind ~/.Renviron.site-rocker:/usr/local/lib/R/etc/Renviron.site