4

I'm experiencing some problems with executing R scripts in my snakemake workflow. It seems that my personal .Rprofile is loaded inside the R script. The job is run inside a singularity container and the problem is that I automatically load some packages in my R profile that are not installed in the container. I could of course solve this by editing my R profile but everybody else who wants to use the pipeline would have to do the same which is something I don't like. Does anybody have an idea how to solve this otherwise?

Thanks!

fakechek
  • 239
  • 2
  • 14
  • 2
    I just found this in the source code of snakemake (`script.py`): `elif path.endswith(".R"): shell("Rscript {f.name}", bench_record=bench_record)`. So I guess it's not possible to pass arguments at the moment. – fakechek Sep 17 '18 at 16:11

2 Answers2

4

You'll find that Rscript:

$ Rscript
Usage: /path/to/Rscript [--options] [-e expr [-e expr2 ...] | file] [args]

--options accepted are
  --no-environ        Don't read the site and user environment files
  --no-site-file      Don't read the site-wide Rprofile
  --no-init-file      Don't read the user R profile
  --vanilla           Combine --no-save, --no-restore, --no-site-file
                        --no-init-file and --no-environ

and R have some options to help you with this:

$ R --help

Usage: R [options] [< infile] [> outfile]
   or: R CMD command [arguments]

Start R, a system for statistical computation and graphics, with the
specified options, or invoke an R tool via the 'R CMD' interface.

Options:
  --no-environ          Don't read the site and user environment files
  --no-site-file        Don't read the site-wide Rprofile
  --no-init-file        Don't read the user R profile
  --vanilla   Combine --no-save, --no-restore, --no-site-file,
      --no-init-file and --no-environ

(other options omitted for brevity)

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • Thanks, now I just have to see if these options can be used inside snakemake (while still using the "script:" interface because otherwise I don't have the snakemake object inside R available). – fakechek Sep 17 '18 at 11:39
1

As @hrbrmstr already suggest, --vanilla was the parameter I wanted to use. However, I couldn't find a way to pass this parameter inside snakemake while still running the R script as a script (which has the advantage of having all the snakemake parameters available inside the R environment). Instead, I went to the source code and edited the script.py file .../lib/python3.6/site-packages/snakemake/script.py:

From

shell("Rscript {f.name}", bench_record=bench_record)

to

shell("Rscript --vanilla {f.name}", bench_record=bench_record)

Works for now.

Cheers!

fakechek
  • 239
  • 2
  • 14
  • 1
    This seems important enough to be worth filing an issue: https://bitbucket.org/snakemake/snakemake/issues/new – merv Sep 19 '18 at 03:14