简体   繁体   English

Snakemake:执行R脚本时忽略Rprofile

[英]Snakemake: Ignore Rprofile when executing an R script

I'm experiencing some problems with executing R scripts in my snakemake workflow. 我在snakemake工作流程中执行R脚本遇到了一些问题。 It seems that my personal .Rprofile is loaded inside the R script. 似乎我的个人.Rprofile被加载到R脚本中。 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. 作业在一个奇点容器内运行,问题是我自动加载了我的R配置文件中没有安装在容器中的一些软件包。 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. 我当然可以通过编辑我的R配置文件来解决这个问题,但是其他想要使用管道的人必须做同样的事情,这是我不喜欢的事情。 Does anybody have an idea how to solve this otherwise? 有人知道如何解决这个问题吗?

Thanks! 谢谢!

You'll find that Rscript : 你会发现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有一些选项来帮助你:

$ 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) (为简洁起见,省略了其他选项)

As @hrbrmstr already suggest, --vanilla was the parameter I wanted to use. 正如@hrbrmstr已经建议的那样, - --vanilla是我想要使用的参数。 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). 但是,我仍然找不到在snakemake中传递此参数的方法,同时仍然将R脚本作为脚本运行(其优点是在R环境中可以使用所有snakemake参数)。 Instead, I went to the source code and edited the script.py file .../lib/python3.6/site-packages/snakemake/script.py : 相反,我去了源代码并编辑了script.py文件.../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! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM