capture.output
Send output to a character string or file
Description
Captures the output from evaluated expressions.
The output lines are either sent to a file
or returned as elements of a character vector.
Usage
capture.output(..., file = NULL, append = FALSE)
Arguments
... |
expressions to be evaluated.
|
file |
the file or connection to where the output is written.
If file is NULL (the default),
capture.output returns a character vector.
|
append |
logical flag: if TRUE, the output is appended to file.
If FALSE (the default), the output overwrites the contents
of file.
|
Value
- If file is NULL, returns a character vector where each element corresponds to a line of the
captured output.
- If file is not NULL, the output is invisible(NULL), and the result is sent to the
specified file.
Side Effects
If file is a character string, the output is written to that file.
If the file exists and append is TRUE, the output is appended
to the end of the file.
If
file is a connection, the output is written to the connection, and
the
append argument is ignored.
- If the connection is open, it should be open in binary mode for
writing.
- If the connection is not yet open, it is opened in binary mode. After
the output data is written, it is closed.
See Also
Examples
capture.output(cat(1:3))
capture.output(data.frame(a=11:13, b=21:23))
capture.output(data.frame(a=11:13, b=21:23), file="dataframe.txt")