[R] How to nicely display R code with the LaTeX package 'listings'?
Marius Hofert
marius.hofert at math.ethz.ch
Thu Nov 1 20:57:00 CET 2012
Dear Yihui, Dear Frank,
Thanks for helping.
I am aware of Sweave and knitr and this is an incredible development. Still,
this "machinery" is too heavy for my needs. I typically use pure R scripts for
my work (well documented with Roxygen). I can then easily debug and
are not disturbed by additional text already. Also, I can easily run a pure R
script on a computer cluster (not sure about an .Rnw -- okay, one might use a
makefile that first tangles it and then sends the script to the cluster, but that
already adds another layer of complexity). Another thing is syncronization
(forward/backward search from .pdf). We recently managed to use Duncan's "patchDVI" to
get backward sync to the .Rnw file instead of the .tex file. This was even in a
multi-file document (several .Rnw loaded from a master file) where it is
extremely useful. But that was not so easy to set up (and I am not sure if knitr
does/can incorporate this). The biggest problem,
however, is portability. None of my co-authors (except for Martin) uses such
tools and is therefore able to compile the .Rnw document (they mostly use .tex
and can compile those documents). So for putting in some lines of code in a
paper, this is quite restrictive (that's why I was hoping for a latex-related
solution -- still asking on r-help since I'd expect R users to have encountered
this issue before).
Cheers,
Marius
Yihui Xie <xie at yihui.name> writes:
> Or see https://github.com/yihui/knitr-examples/blob/master/015-listings.Rnw
> for a minimal example.
>
> Regards,
> Yihui
> --
> Yihui Xie <xieyihui at gmail.com>
> Phone: 515-294-2465 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
>
>
> On Thu, Nov 1, 2012 at 1:23 PM, Frank Harrell <f.harrell at vanderbilt.edu> wrote:
>> The knitr package makes this relatively easy to do. See for example
>> http://biostat.mc.vanderbilt.edu/KnitrHowto
>>
>> Frank
>>
>>
>> Marius Hofert-3 wrote
>>> Dear expeRts,
>>>
>>> What's a 'good' (nice-looking, easy-to-read) setup for the LaTeX package
>>> 'listings' to display R code?
>>>
>>> The two versions below are partly inspired by the settings of the package
>>> SweaveListingUtils and
>>> http://r.789695.n4.nabble.com/R-How-to-format-R-code-in-LaTex-documents-td816055.html
>>>
>>> Any suggestions, comments, or improvements are welcome.
>>>
>>> Cheers,
>>>
>>> Marius
More information about the R-help
mailing list