capture {gtools}R Documentation

Capture printed output of an R expression in a string

Description

Capture printed output of an R expression in a string

Usage

capture(expression, collapse = "\n")
sprint(x,...)

Arguments

expression R expression whose output will be captured.
collapse Character used to join output lines. Defaults to "\n". Use NULL to return a vector of individual output lines.
x Object to be printed
... Optional parameters to be passed to print

Details

The capture function uses sink to capture the printed results generated by expression.

The function sprint uses capture to redirect the results of calling print on an object to a string.

Value

A character string, or if collapse==NULL a vector of character strings containing the printed output from the R expression.

WARNING

R 1.7.0+ includes capture.output, which duplicates the functionality of capture. Thus, capture is depreciated.

Author(s)

Gregory R. Warnes warnes@bst.rochester.edu

See Also

texteval, capture.output

Examples


# capture the results of a loop
loop.text <- capture( for(i in 1:10) cat("i=",i,"\n") )
loop.text

# put regression summary results into a string
data(iris)
reg <- lm( Sepal.Length ~ Species, data=iris )
summary.text <- sprint( summary(reg) )
cat(summary.text)

[Package gtools version 2.4.0 Index]