[R] inserting R code in a latex document

Uwe Ligges ligges at statistik.uni-dortmund.de
Wed May 11 10:09:07 CEST 2005

Thibaut Jombart wrote:

> Hello,
> I'm trying to insert R source code (functions) in an appendix of a latex 
> document. I guess the easiest way to do so is to use the package Sweaved 
> (file : Sweaved.sty) provided with the latest R version. Latex succeeds 
> in loading the package, but my problem comes from the use of this very 
> package. I tried to use the 'Schunk' environment, but '#' characters 
> generate error (my R functions are annotated, and I want to keep those 
> annotations). Under the 'Sinput' environment, no error is generated but 
> the result is simply not different from what would be obtained under 
> 'verbatim' environment : R code lines are cut as they don't fit in the 
> page width.
> I tried to find answers in the latest Sweaved User Manual, 
> unsuccessfully. I'm a recent latex user and I doubt I can quickly find a 
> solution by myself.

I think we are talking about "Sweave" in package "utils"?
If so, you will find that you have to re-read the manual, because you 
don't need to specify 'Schunk'/'Sinput' yourself: Sweave does it for 
you. Just write the code in code chunks such as

# comment
LaTeX code

and apply Sweave on your noweb document, the resulting LaTeX document 
has appropriate environments.

Uwe Ligges

> Thanks,
> Thibaut Jombart
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html

More information about the R-help mailing list