[R] R batch mode options

Al Piszcz apiszcz at solarrain.com
Wed Aug 25 12:19:51 CEST 2004



I have raised this in the past, the solution I would like to
see is something like getopts. However the following
offers a possible solution.



FILE: Rba
---------------------------------------------------
#!/bin/sh
##
## ARG 1 is the R program to RUN
## rest of line are arguments

if [ $# -eq 0 ] ; then
   echo
   echo "usage: Rba RPROGRAM.r ARG1 ARG2 ...."
   echo
   exit
fi


program=$1
shift
cmdargs=$*

gtime R --quiet \
   --no-save \
   $cmdargs < $program
-----------------------------------------------------
Inside your R function/program/module you
access command line arguments 'userargs'.


EXAMPLE
-----------------------------------------------------
   # set parameters from commandline
   inputfile<-userargs[4]
   outputfile<-userargs[5]




More information about the R-help mailing list