[R] Best use of LaTeX listings package for pretty printing R code

Frank E Harrell Jr f.harrell at vanderbilt.edu
Mon Sep 25 15:31:37 CEST 2006

This is what I have been using.  Does anyone have a better way?  In 
particular I would like to see letters in comment strings not stretched 
so much.  Thanks -Frank


  xleftmargin=4ex,literate={<-}{{$\leftarrow$}}1 {~}{{$\sim$}}1}
\lstset{escapeinside={(*}{*)}}   % for (*\ref{ }*) inside lstlistings (S 
a <- b   # this is a test line
if(i==3) {  # another line, for y^2
  y <- 3^3
  z <- 'this string'
  qqcat <- y ~ pol(x,2)
} else y <- 4
That was \lstinline|x <- 22| \lil{q <- 'cat'}.

Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University

More information about the R-help mailing list