[R] Truncated R output in Sweave
Frank E Harrell Jr
f.harrell at vanderbilt.edu
Sat Jun 6 23:14:26 CEST 2009
Romain Francois wrote:
>
>
> Frank E Harrell Jr wrote:
>>
>> Dear Colleagues:
>>
>> In producing a book or a handout I sometimes cut out a large part of
>> the printed output of an R function, substituting ... for that chunk.
>> Deleting non-essential output saves paper. It would be nice to have a
>> capability in Sweave to allow the user to specify a starting and an
>> ending regular expression that would identify consecutive lines of
>> output to replace with ..., without showing the extra code required to
>> do this to the user. I would want the LaTeX output, other than the
>> omission, to appear the same as if the section were not omitted. Does
>> anyone have an idea of how to do this elegantly?
>
> Hello,
>
> You could use the same trick that is sometimes used to embed lattice
> calls into print calls (see the grid vignette for example)
>
> \documentclass[a4paper]{article}
> \begin{document}
> <<aa,eval=FALSE,echo=T>>=
> rnorm( 200 )
> <<echo=F>>=
> txt <- capture.output( {
> <<aa>>
> } )
> if( length(txt) > 10 ){
> txt <- c( txt[1:10], "..." )
> }
> cat( txt, sep = "\n" )
> @
> \end{document}
Thank you Romain - I did not know of that construct.
>
>>
>> By the way I just discovered the SweaveListingUtils package by Peter
>> Ruckdeschel (on CRAN), which produces beautifully printed R code in
>> Sweave code chunks. I put some info about it at
>> http://biostat.mc.vanderbilt.edu/SweaveTemplate which has our Sweave
>> template for statistical reports.
> You might also be interested by the driver that comes with the highlight
> package (not yet on cran though, but the r-forge version is stable enough).
>
> > install.packages("highlight", repos="http://R-Forge.R-project.org")
> > require( highlight )
> > Sweave( file, driver = HighlightWeaveLatex() )
Interesting. What would be the corresponding batch file command to
achieve this? I like to run R CMD Sweave my.Rnw. And would you mind
giving a very brief comparison of the two highlighting approaches
regarding the LaTeX output?
Thanks!
Frank
> *||*
>>
>> Thanks
>> Frank
>
>
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
More information about the R-help
mailing list