\HeaderA{BATCH}{Batch Execution of R}{BATCH}
\keyword{utilities}{BATCH}
\begin{Description}\relax
Run \R{} non-interactively with input from \code{infile} and
send output (stdout/stderr) to another file.
\end{Description}
\begin{Usage}
\begin{verbatim}
R CMD BATCH [options] infile [outfile]
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{infile}] the name of a file with \R{} code to be executed.
\item[\code{options}] a list of \R{} command line options, e.g., for setting the
amount of memory available and controlling the load/save process.
If \code{infile} starts with a \samp{-}, use \samp{--} as the final
option.  The default options are \samp{--restore --save --no-readline}.
\item[\code{outfile}] the name of a file to which to write output.  If not
given, the name used is that of \code{infile}, with a possible
\file{.R} extension stripped, and \file{.Rout} appended.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Use \code{R CMD BATCH --help} to be reminded of the usage.

By default, the input commands are printed along with the output.  To
suppress this behavior, add \code{options(echo = FALSE)} at the
beginning of \code{infile}, or use option \samp{--slave}.

The \code{infile} can have end of line marked by LF or CRLF (but not
just CR), and files with an incomplete last line (missing end of line
(EOL) mark) are processed correctly.

A final expression \samp{proc.time()} will be executed after the input
script unless the latter calls \code{\LinkA{q}{q}(runLast=FALSE)} or is aborted.

Additional options can be set by the environment variable
\code{R\_BATCH\_OPTIONS}: these come after \samp{--restore --save
--no-readline} and before any options given on the command line.
\end{Details}
\begin{Note}\relax
Unlike \code{Splus BATCH}, this does not run the \R{} process in the
background.  In most shells,
\code{R CMD BATCH [options] infile [outfile] \&}
will do so.

Report bugs to \email{r-bugs@r-project.org}.
\end{Note}

