\HeaderA{capture.output}{Send output to a character string or file}{capture.output}
\keyword{utilities}{capture.output}
\begin{Description}\relax
Evaluates its arguments with the output being returned as a character
string or sent to a file.  Related to \code{\LinkA{sink}{sink}} in the same
way that \code{\LinkA{with}{with}} is related to \code{\LinkA{attach}{attach}}.
\end{Description}
\begin{Usage}
\begin{verbatim}
capture.output(..., file = NULL, append = FALSE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{...}] Expressions to be evaluated.
\item[\code{file}] A file name or a connection, or \code{NULL} to return
the output as a character vector.  If the connection is not open,
it will be opened initially and closed on exit.
\item[\code{append}] logical.  If \code{file} a file name or unopened
connection, append or overwrite?
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
An attempt is made to write output as far as possible to \code{file}
if there is an error in evaluating the expressions, but for \code{file
    = NULL} all output will be lost.
\end{Details}
\begin{Value}
A character string (if \code{file=NULL}), or invisible \code{NULL}.
\end{Value}
\begin{SeeAlso}\relax
\code{\LinkA{sink}{sink}}, \code{\LinkA{textConnection}{textConnection}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
require(stats)
glmout <- capture.output(example(glm))
glmout[1:5]
capture.output(1+1, 2+2)
capture.output({1+1; 2+2})
## Not run: 
## on Unix with enscript available
ps <- pipe("enscript -o tempout.ps","w")
capture.output(example(glm), file=ps)
close(ps)
## End(Not run)
\end{ExampleCode}
\end{Examples}

