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 rnorm(100) produces about 20 lines of output (depending on options("width")). I'd prefer something like: rnorm(100) [1] 0.527739021 0.185551107 -1.239195562 0.020991608 -1.225632520 [6] -1.000243373 -0.020180393 2.552180776 -1.719061533 -0.195024625 ... [96] -0.744916379 0.863733400 -0.186667848 1.378236663 -0.499201046 The actual application would be printing of output from summary() methods. Ideally it would be nice to ask for line 1-10, 30-40, 100-102, for example, so you could print the first few lines of several sections of output. I'd like to automate this so I don't need to keep copying and pasting into the final tex source or forget to do it if I alter some previous part of the Sweave source. Has anyone tried to do this? Does anyone know of an automatic way of achieving the simple abbreviation or the more complicated version I described? Any thoughts on this? 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. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
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 > > rnorm(100) > > produces about 20 lines of output (depending on options("width")). I'd > prefer something like: > > rnorm(100) > [1] 0.527739021 0.185551107 -1.239195562 0.020991608 -1.225632520 > [6] -1.000243373 -0.020180393 2.552180776 -1.719061533 -0.195024625 > ... > [96] -0.744916379 0.863733400 -0.186667848 1.378236663 -0.499201046 > > The actual application would be printing of output from summary() > methods. Ideally it would be nice to ask for line 1-10, 30-40, 100-102, > for example, so you could print the first few lines of several sections > of output. I'd like to automate this so I don't need to keep copying and > pasting into the final tex source or forget to do it if I alter some > previous part of the Sweave source. > > Has anyone tried to do this? Does anyone know of an automatic way of > achieving the simple abbreviation or the more complicated version I > described? > > Any thoughts on this? >Maybe you could use head(rnorm(100)) instead. Check ?head for other arguments.
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 > > rnorm(100) > > produces about 20 lines of output (depending on options("width")). I'd > prefer something like: > > rnorm(100) > [1] 0.527739021 0.185551107 -1.239195562 0.020991608 -1.225632520 > [6] -1.000243373 -0.020180393 2.552180776 -1.719061533 -0.195024625 > ... > [96] -0.744916379 0.863733400 -0.186667848 1.378236663 -0.499201046 > > The actual application would be printing of output from summary() > methods. Ideally it would be nice to ask for line 1-10, 30-40, 100-102, > for example, so you could print the first few lines of several sections > of output. I'd like to automate this so I don't need to keep copying and > pasting into the final tex source or forget to do it if I alter some > previous part of the Sweave source. > > Has anyone tried to do this? Does anyone know of an automatic way of > achieving the simple abbreviation or the more complicated version I > described?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> > Any thoughts on this? > > Thanks in advance, > > Gav >-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no