[R] Sweave and abbreviating output from R

Gavin Simpson gavin.simpson at ucl.ac.uk
Mon Apr 11 14:12:04 CEST 2005


Gabor Grothendieck wrote:
> On Apr 11, 2005 7:22 AM, Gavin Simpson <gavin.simpson at ucl.ac.uk> 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>
>>
>>Any thoughts on this?
>>
> 
> 
> Maybe you could use head(rnorm(100)) instead.  Check ?head
> for other arguments.
> 
>

Thanks for this Gabor. Head/tail works just fine for my rnorm example, 
but for printed output from summary methods for example it doesn't quite 
work as I would like.

But that got me thinking a bit more and I remembered capture.output() 
and I saw that noquote() is used in head.function(). So, I can now get 
this far:

noquote(capture.output(summary(pondsca)))[1:10]
  [1] 

  [2] Call: 

  [3] 

  [4] Partitioning of mean squared contingency coefficient: 

  [5] 

  [6] Total         4.996 

  [7] Unconstrained 4.996 

  [8] 

  [9] Eigenvalues, and their contribution to the mean squared 
contingency coefficient
[10] 


Now all I need is to find out how to print without the indices 
[1],[2]...[n] being printed?

Also, I noticed that with some objects, more than one "line" of output 
is printed per line - just like a vector would. In the example below we 
see 3 "lines" of output printed per row.

x <- rnorm(100)
y <- rnorm(100)
noquote(capture.output(summary(lm(x ~ y))))[1:5]
[1]                     Call:               lm(formula = x ~ y)
[4]                     Residuals:

Is there a way to print only a single element of a vector per line?

Thanks in advance.

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