Re: [R] Sweave and abbreviating output from R

From: Gavin Simpson <gavin.simpson_at_ucl.ac.uk>
Date: Mon 11 Apr 2005 - 23:47:42 EST

Roger Bivand wrote:
> On Mon, 11 Apr 2005, Gavin Simpson wrote:
>
>

>>Dear List,
>>
>>I'm using Sweave to produce a series of class handouts for a course I am 
>>running. The students in previous years have commented about wanting 
>>output within the handouts so they can see what to expect the output to 
>>look like. So Sweave is a godsend for producing this type of handout - 
>>with one exception: Is there a way to suppress some rows of printed 
>>output so as to save space in the printed documentation? E.g
<snip>
>
>
> Semi-automatic is:
>
>
>>res <- capture.output(rnorm(100))
>>cat(res[1:2], "...", res[length(res)], sep="\n")

>
>
> but I've found that 1) it needs masking from the users, and 2) it is
> difficult to automate when the numbers of output lines generated by print
> methods vary with input data (like in print.htest()). But capture.output
> is very useful.
>
> Roger
>

Thanks Roger - that got it! using combinations of:

<<echo=true,eval=FALSE>>=
summary(pondspca, scaling = 2)
@
<<echo=false,eval=true>>=
out <- capture.output(summary(pondspca)) cat(out[1:27], "....", out[43:48], "....", sep = "\n") @

displays the relevant commands to the user but hides the semi-automatic printing of the selected sections.

All the best,

Gav

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson                     [T] +44 (0)20 7679 5522
ENSIS Research Fellow             [F] +44 (0)20 7679 7565
ENSIS Ltd. & ECRC                 [E] gavin.simpsonATNOSPAMucl.ac.uk
UCL Department of Geography       [W] http://www.ucl.ac.uk/~ucfagls/cv/
26 Bedford Way                    [W] http://www.ucl.ac.uk/~ucfagls/
London.  WC1H 0AP.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue Apr 12 09:39:19 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:06 EST