Skip to content

R-code in R-file documentation

3 messages · Brian, Ben Bolker, Yihui Xie

#
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
#
Brian Oney <zenlines <at> gmail.com> writes:
[snip]

  Wouldn't it be easier to use the LaTeX listings package?
<https://stat.ethz.ch/pipermail/r-help/2006-September/113688.html>
<https://stat.ethz.ch/pipermail/r-help/2006-September/113103.html>
#
I guess what you want is cat(readLines("file.r"), sep = "\n")

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 Wed, May 18, 2011 at 4:03 AM, Brian Oney <zenlines at gmail.com> wrote: