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,
               type = c("output", "message"), split = 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.
type a character vector with the value "output" or "message". If type is "output", output to stdout() is captured. If type is "message", output to stderr() is captured.
split a logical flag. If TRUE, output is captured, and also sent to the current output stream. If FALSE (the default), the output is not split. When type is "message", split should always be FALSE.
Value
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 type is "output", capturing can be nested; that is, if capture.output is called while output is being captured, the previous capture is suspended, and then resumed when the nested capture.output is finished. If type is "message", nesting is not supported.
See Also
cat, sink
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")
Package utils version 6.0.0-69
Package Index