snakemake / snakemake

This is the development home of the workflow management system Snakemake. For general information, see
https://snakemake.github.io
MIT License
2.18k stars 524 forks source link

Rmarkdown render is not compatible with a renv environment #490

Open JulioV opened 3 years ago

JulioV commented 3 years ago

Snakemake version 5.7.1

Describe the bug When executing a rule targeting a Rmarkdown file, the command fails because the package rmarkdown cannot be loaded. This happens because rmarkdown has been installed with renv but the vanilla flag in 'Rscript --vanilla -e \'rmarkdown::render("{fname}"... ignores the local .Rprofile

https://github.com/snakemake/snakemake/blob/53afe6d1cbea058de3ad440062c751167d2e463b/snakemake/script.py#L737

Logs

Error in loadNamespace(name) : there is no package called 'rmarkdown'
Calls: :: ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted

Additional context I'm not sure what would be the best way to solve this? Remove the vanilla option? Have a flag to source a packrat/renv environement (renv/activate.R)?

karldw commented 3 years ago

I've run into similar issues. Things get more complicated if the user has rmarkdown installed in their personal library and has R_LIBS_USER set to point to that library. In that case, the command you mentioned will load the user's home copy of rmarkdown, which can cause unexpected problems if the versions of rmarkdown don't match up.

It might be possible to set R_LIBS_USER locally, something like:

R_LIBS_USER=renv/library/R-4.0/x86_64-pc-linux-gnu Rscript --vanilla ....