[R] R-code in R-file documentation

Brian Oney zenlines at gmail.com
Wed May 18 11:03:53 CEST 2011


Hello List,
I would like to insert code from .r files into a LaTeX appendix 
(possibly using Sweave).
I was considering:

<<results=tex,eval=true,echo=true>>=
source("file.r")
@
but I would just like to echo the code and not evaluate the code within 
the file.
maybe:
<<results=tex,eval=true,echo=false>>=
cat("\\begin{verbatim}")
readLines("file.r")
cat("\\end{verbatim}")
@

The above works well other than the line numbers which are included 
(which isn't so bad).

Thanks for the help and ideas!
Brian



More information about the R-help mailing list