2

How can I set R options (e. g. options(keep.source = TRUE)) individually for R scripts that I execute via Rscript?

In the Rscript docs I cannot find such a command line argument.

I want to run the same R script with different options.

My goal is to separate my R scripts and options (settings) and I want to avoid changing my R scripts manually to inject different options.

I have already tried using expressions and a file but this does not work:

Rscript --verbose -e "options(keep.source = TRUE)" my_script.R

It returns nothing and does not start my_script.R.

R Yoda
  • 8,358
  • 2
  • 50
  • 87
  • @sebastian-c Similar, but not the same IMHO. I want to set/initialize R options (`options` function), NOT pass command line arguments to my script. This is a little bit different I think since the script is completely agnostic of setting options. – R Yoda Nov 03 '16 at 08:59
  • Maybe I'm missing something, but could you do something like `options(keep.source = !is.na(commandArgs(trailingOnly = TRUE)[1]))`? Alternatively, have a master script which takes a script name as an argument. – sebastian-c Nov 03 '16 at 09:14
  • @sebastian-c Yes, I could explicitly process options like you indicated, but not for a number of arguments not known beforehand. In fact currently I use a master script that I execute to inject my options and which then calls the real script passed as normal argument. In my question I am trying to find a different solution I am investigating and it seems to me that `Rscript` does not offer a simple way to inject options via the command line. Thx for your proposals above :-) – R Yoda Nov 03 '16 at 09:21

0 Answers0