in reply to Passing parameters to R script

# test.R:

cat("-- reading arguments\n", sep = ""); cmd_args = commandArgs(); for (arg in cmd_args) cat(" ", arg, "\n", sep="");

# command line:

R --slave --no-save --no-restore --no-environ --silent --args arg1=abc + < test.R

# output from R:

-- reading arguments /home/aardvark/lib/R/bin/exec/R --slave --no-save --no-restore --no-environ --silent --args arg1=abc

Replies are listed 'Best First'.
Re^2: Passing parameters to R script
by j1n3l0 (Friar) on Oct 15, 2007 at 21:39 UTC
    Thank you very much! This is precisely what I was looking for =)

    Now I need to tweak it a bit for my needs. Thank you soooooooooo much!


    Smoothie, smoothie, hundre prosent naturlig!
      very late answer, maybe the library is newer than your question, but what about optparse or getopt?
      install.packages('optparse') ?optparse
      I tried to get it working (I come from Python and I'm used to the syntax) but in the end I settled for the easier (and working) 'getopt' solution:
      install.packages('getopt') . . . if(require("getopt", quietly=TRUE)) { opt <- getopt(matrix(c('path', 'p', 1, "character"), ncol=4, byrow=TRUE)) if(!is.null(opt$path)) path <- opt$path }