capture.and.write | R Documentation |
Capture output and print first and last parts, eliding
middle parts. Particularly useful for teaching purposes, and, e.g.,
in Sweave (RweaveLatex
).
By default, when middle = NA
, capture.output(EXPR, first, last)
basically does
co <- capture.output(EXPR) writeLines(head(co, first)) cat( ... dotdots ...) writeLines(tail(co, last))
capture.and.write(EXPR, first, last = 2, middle = NA,
i.middle, dotdots = " ....... ", n.dots = 2)
EXPR |
the (literal) expression the output of which is to be captured. |
first |
integer: how many lines should be printed at beginning. |
last |
integer: how many lines should be printed at the end. |
middle |
numeric (or NA logical): |
i.middle |
index start of middle part |
dotdots |
string to be used for elided lines |
n.dots |
number of |
return value of capture.output(EXPR)
.
Martin Maechler, ETH Zurich
head
, tail
x <- seq(0, 10, by = .1)
## for matrix, dataframe, .. first lines include a header line:
capture.and.write( cbind(x, log1p(exp(x))), first = 5)
## first, *middle* and last :
capture.and.write( cbind(x, x^2, x^3), first = 4, middle = 3, n.dots= 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.