| 1 |
\name{capture.and.write} |
| 2 |
\alias{capture.and.write} |
| 3 |
\title{Capture output and Write / Print First and Last Parts} |
| 4 |
\description{ |
| 5 |
Capture output and print first and last parts, eliding |
| 6 |
middle parts. Particularly useful for teaching purposes, and, e.g., |
| 7 |
in Sweave (\code{\link{RweaveLatex}}). |
| 8 |
|
| 9 |
By default, when \code{middle = NA}, \code{capture.output(EXPR, first, last)} |
| 10 |
basically does |
| 11 |
\preformatted{ |
| 12 |
co <- capture.output(EXPR) |
| 13 |
writeLines(head(co, first)) |
| 14 |
cat( ... dotdots ...) |
| 15 |
writeLines(tail(co, last)) |
| 16 |
} |
| 17 |
} |
| 18 |
\usage{ |
| 19 |
capture.and.write(EXPR, first, last = 2, middle = NA, |
| 20 |
i.middle, dotdots = " ....... ", n.dots = 2) |
| 21 |
} |
| 22 |
\arguments{ |
| 23 |
\item{EXPR}{the (literal) expression the output of which is to be |
| 24 |
captured.} |
| 25 |
\item{first}{integer: how many lines should be printed at beginning.} |
| 26 |
\item{last}{integer: how many lines should be printed at the end.} |
| 27 |
\item{middle}{numeric (or NA logical):} |
| 28 |
\item{i.middle}{index start of middle part} |
| 29 |
\item{dotdots}{string to be used for elided lines} |
| 30 |
\item{n.dots}{number of \code{dotdots} lines added between parts.} |
| 31 |
} |
| 32 |
\value{ |
| 33 |
return value of \code{\link{capture.output}(EXPR)}. |
| 34 |
} |
| 35 |
\seealso{ |
| 36 |
\code{\link{head}}, \code{\link{tail}} |
| 37 |
} |
| 38 |
\author{Martin Maechler, ETH Zurich} |
| 39 |
\examples{ |
| 40 |
x <- seq(0, 10, by = .1) |
| 41 |
|
| 42 |
## for matrix, dataframe, .. first lines include a header line: |
| 43 |
capture.and.write( cbind(x, log1p(exp(x))), first = 5) |
| 44 |
|
| 45 |
## first, *middle* and last : |
| 46 |
capture.and.write( cbind(x, x^2, x^3), first = 4, middle = 3, n.dots= 1) |
| 47 |
} |
| 48 |
%% some of MM's own "real use" examples: |
| 49 |
%% ~/R/Meetings-Kurse-etc/2012-Rmpfr-ZurichR/BinCoef.Rnw |
| 50 |
%% ~/R/MM/NUMERICS/log1exp/log1exp-note.Rnw |