[R] including Sweave tangled code in '.Rnw' document

Vincent Goulet vincent.goulet at act.ulaval.ca
Sun Nov 30 17:42:36 CET 2008


Kyle,

In addition to "listings" already mentioned by Berwin, you may find  
useful the "answers" package. This is what I use to create assignments/ 
exams/exercise sets with solutions all in one file.

HTH

Vincent

---
   Vincent Goulet, Associate Professor
   École d'actuariat
   Université Laval, Québec
   Vincent.Goulet at act.ulaval.ca   http://vgoulet.act.ulaval.ca

Le sam. 29 nov. à 14:11, Kyle Matoba a écrit :

> Hello List,
>
> I have been using Sweave for my homework this last quarter and have  
> been
> very impressed at how much time and effort it saves me.  I, however,  
> have
> run up against a problem which I have not been able to solve using  
> any of
> the Sweave/LaTeX tricks I know.  I work through my homework one  
> problem at a
> time, typesetting equations and writing R code, etc. and  
> occasionally use
> 'Stangle()' from within R to extract the code if I need to pin down a
> problem or experiment interactively.  I would like to be able to  
> include
> this resultant code in a verbatim environment in my final TeX'ed up  
> document
> as an appendix so that the grader can look it over, etc.  I could  
> implement
> this in any number of ways using linux tools, but would like to know  
> if
> there is a clean way to do so using LaTeX or Sweave so that the latest
> version of the code is included in my homework each time I run 'R  
> CMD Sweave
> HW4.Rnw; pdflatex HW4.tex'.
>
> e.g I envision something such as:
>
> \begin{document}
> <<fig3, echo=false, results=hide, fig=true, eps=F>>=
> plot(runif(1000))
> @
>
> TA here is my code:
>
> % some manner of Sweave/LaTeX macro to include the R code tangled  
> out of
> this '.Rnw' document
> % in this case it would just be 'plot(runif(1000))', perhaps manually
> enclosed in a verbatim environment
>
> \end{document}
> I am running R-2.6.2 on Ubuntu Hardy Heron.
>
>
> Thanks for all your help with Sweave.  I think it is a fantastic tool.
>
> Kyle
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list