Monday, March 11, 2013

Reading Command Line args in R

I'm writing this down in my blog because I keep forgetting my standard way for adding command line arguments to R. I like to use executable R scripts that don't require --vanilla --args etc. The syntax in the R script is:



script.R:
 
#!/usr/bin/env Rscript
argv <- commandArgs(trailingOnly=TRUE)

Make it executable:
chmod +x script.R
Execute with
./script.R extra arguments go here

I prefer this method much more than others because the R script acts like any other command line tool now.

No comments:

Post a Comment