Skip to content
Prev 5463 / 398502 Next

including r code in a latex file

On Mon, 1 May 2000, Faheem Mitha wrote:

            
While you could use verbatim, as others have suggested, the lgrind
definitions that I posted here the other day has been written with that in
mind to produce nice R-code program listings for inclusion in LaTeX
documents. 

lgrind is a pretty standard program, you may find it on you system. I
haven't myself been able to make it work, for some unknown reason, but if
you take the following code:
R:\
        :pb=^\d?\p\d<-\dfunction\(\a\):\
        :bb={:be=}:cb=\d#:ce=$sb=":se=\e":lb=':le=\e':id=.:\
        :zb=@:ze=@:tb=%%:te=%%:mb=%\$:me=\$%:vb=%\|:ve=\|%:\
        :kw=while for in repeat if else switch break next\
        return stop warning function:
save it to a file you call e.g. ~/tex/lgrindefs
then running
lgrind -i -d ~/tex/lgrindefs mycode.R > mycode.tex
should produce a nice LaTeXed file. I think... You need to include the
lgrind style file in you document, as well as use a macro to include it.
See the lgrind(1) man page for details

Best,

Kjetil