capture-n-write.RdCapture 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)the (literal) expression the output of which is to be captured.
integer: how many lines should be printed at beginning.
integer: how many lines should be printed at the end.
numeric (or NA logical):
index start of middle part
string to be used for elided lines
number of dotdots lines added between parts.
return value of capture.output(EXPR).
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)
#> x
#> [1,] 0.0 0.6931472
#> [2,] 0.1 0.7443967
#> [3,] 0.2 0.7981389
#> [4,] 0.3 0.8543552
#> .......
#> .......
#> [100,] 9.9 9.9000502
#> [101,] 10.0 10.0000454
## first, *middle* and last :
capture.and.write( cbind(x, x^2, x^3), first = 4, middle = 3, n.dots= 1)
#> x
#> [1,] 0.0 0.00 0.000
#> [2,] 0.1 0.01 0.001
#> [3,] 0.2 0.04 0.008
#> .......
#> [49,] 4.8 23.04 110.592
#> [50,] 4.9 24.01 117.649
#> [51,] 5.0 25.00 125.000
#> .......
#> [100,] 9.9 98.01 970.299
#> [101,] 10.0 100.00 1000.000