Passing command line arguments to R CMD BATCH

前端 未结 6 659
你的背包
你的背包 2020-11-27 09:22

I have been using R CMD BATCH my_script.R from a terminal to execute an R script. I am now at the point where I would like to pass an argument to

6条回答
  •  甜味超标
    2020-11-27 09:55

    You need to put arguments before my_script.R and use - on the arguments, e.g.

    R CMD BATCH -blabla my_script.R
    

    commandArgs() will receive -blabla as a character string in this case. See the help for details:

    $ R CMD BATCH --help
    Usage: R CMD BATCH [options] infile [outfile]
    
    Run R non-interactively with input from infile and place output (stdout
    and stderr) to another file.  If not given, the name of the output file
    is the one of the input file, with a possible '.R' extension stripped,
    and '.Rout' appended.
    
    Options:
      -h, --help        print short help message and exit
      -v, --version     print version info and exit
      --no-timing           do not report the timings
      --            end processing of options
    
    Further arguments starting with a '-' are considered as options as long
    as '--' was not encountered, and are passed on to the R process, which
    by default is started with '--restore --save --no-readline'.
    See also help('BATCH') inside R.
    

提交回复
热议问题