Converting R to Sweave (Rnw)
On 3/2/2009 10:12 AM, Duncan Murdoch wrote:
On 3/2/2009 9:06 AM, Rainer M Krug wrote:
Hi I am thinking about using Sweave more frequently, especially for documenting code. But the syntax is slightly awkward for me (<<name>>= ... @), and I was thinking if there would be a way of importing the type of code extracted from an Rnw file back into an Rnw file? The advantage would be that the code could run in R without tangling. Obviously, sweave options could not be imported, but that would be fine for me. Below an example of the code generated by Rtangle, which I would like to import into a sweave file.
I don't think so, but writing a new driver is only a medium difficulty job. Start with an existing one in https://svn.r-project.org/R/trunk/src/library/utils/R/Sweave.R and modify until you have what you want. The harder part of this is the design: exactly what input and output is not going to be awkward? A different approach to the same problem is to use specially formatted comments in the R source to generate documentation; I think the R.oo package includes such a thing, and there may be others. I haven't used these with R, but have in other languages, and they were nice there.
Actually, the package I was thinking of was roxygen (on CRAN), but I couldn't remember the name and a search came up with the R.oo reference. So there appear to be at least two such systems. Duncan Murdoch
Duncan Murdoch
Cheers Rainer ################################################### ### chunk number 1: a ################################################### x <- 10 ################################################### ### chunk number 2: ################################################### asequence<- seq(from=0,to=5,by=0.1) expnegx2 <- exp(-asequence^2) plot(asequence,expnegx2,type="l",ylab=expression(exp(-z^2)),xlab="z") ################################################### ### chunk number 3: Normal1 ################################################### mu <- 3 sigma <- 5 -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Faculty of Science Natural Sciences Building Private Bag X1 University of Stellenbosch Matieland 7602 South Africa
______________________________________________ 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.
______________________________________________ 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.