[R] Sweave and abbreviating output from R

Gavin Simpson gavin.simpson at ucl.ac.uk
Mon Apr 11 15:47:42 CEST 2005


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.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%




More information about the R-help mailing list