#!/bin/sh
#
# ${R_HOME}/bin/BATCH

revision='$Revision: 1.13 $'
version=`set - ${revision}; echo ${2}`
version="R batch front end ${version}

Copyright (C) 2000--2003 The R Core Development Team.
This is free software; see the GNU General Public Licence version 2
or later for copying conditions.  There is NO warranty."

opts="--restore --save --no-readline --gui=none"

usage="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
  --			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 '$opts'.
See also help(BATCH) inside R;

Report bugs to <r-bugs@r-project.org>."

while test -n "${1}"; do
  case ${1} in
    -h|--help)
      echo "${usage}"; exit 0 ;;
    -v|--version)
      echo "${version}"; exit 0 ;;
    --min-vsize|--min-nsize|--max-vsize|--max-nsize|--vsize|--nsize)
      # Deprecated (hence not documented)...
      opts="${opts} ${1}=${2}"; shift 2 ;;
    --) shift; break ;;
    -*) opts="${opts} ${1}"; shift ;;
    *)  break ;;
  esac
done

in=${1}
out=${2-`basename ${1} .R`.Rout}

(echo "invisible(options(echo = TRUE))"
  cat ${in}
  echo "proc.time()"
) | ${R_HOME}/bin/R ${opts} >${out} 2>&1

### Local Variables: ***
### mode: sh ***
### sh-indentation: 2 ***
### End: ***