Sweave to R markdown file conversion - code or converters available?

r, r-markdown, sweave

Solution

As @Karl commented, LaTeX --> markdown is not a trivial conversion as there are far more options and environments available in LaTeX compared to markdown. You are probably best off working with something like pandoc (see Demo #5). Basically, instead of doing

.Rnw --> .Rmd --> .md

you would do

.Rnw --> .tex --> .md

with pandoc. If you really want to go from .Rnw --> .Rmd, you may want to check out the pander package to write a function to extract code chunks, convert the remaining LaTeX content to markdown, and then re-insert the code chunks into the markdown document.

Problem

I am not sure if this type of question complies with the SO rules for well-defined questions ;) ... anyway: I want to convert several R Sweave files (`.Rnw`) to R markdown files (`.Rmd`). Jeromy Anglin has posted on this matter here but there is no code supplied. I tried to use `pandoc`, but of course `pandoc` cannot handle the chunk tags and inline code tags correctly. Consclusion: I guess I will have do write some code to parse my `.Rnw` files to prepare them for `pandoc` conversion. Thus my questions: - Is there a better way to go? - Does someone by chance have code available that will do the job? TIA

Original source