Convert rmarkdown .Rmd file to (knitr) sweave (.Rnw) - r

I have a rmarkdown document (.Rmd) that I've been doing some analysis in. I now realize I would prefer the functionality of LaTeX. Is there an easy way to convert the file to .Rnw, preserving the chunks (not just the body text)? Articles seem to concentrate on converting the output (i.e. from .html to .pdf) or from sweave to markdown.

Related

Converting .Docx with images to Rmarkdown not working well

I have a word document with notes from a class. In this document there are images (screenshots from the lecture). I am hoping to make a book, hopefully in bookdown, to help me organize my notes and my R code. I used pandoc to convert the word document and extracted the images, but only some of the images are showing up when i knit the markdown output in RStudio. Any idea why some would show and some wouldnt? COuld it be because i'm changing the .md that pandoc gives to .rmd and they just dont play well together?

R Markdown - no ODT and LaTeX options as an output

I found R markdown/knitr useful tool to document my work and generate summary document.
I work with .Rmd (R markdown) files in RStudio.
It seems that knitr provide appropriate functionality to generate .odt (Open Document Text) and .tex (LaTeX) documents from .Rmd.
However, R studio allows to choose .docx, .html and .pdf formats only.
I would like to avoid MS Word format since I prefer open standards and working under Linux.
Is it possible to add .odt and .tex options to Rstudio menu?
It doesn't seem possible to output odt directly in RStudio, but you can always use knitr::knit to produce a markdown document and pandoc to produce the odt:
library(knitr)
knit("myDoc.Rmd")
system("pandoc myDoc.md -o myDoc.odt")
You may have to adjust the pandoc options and adapt the template to get a nice looking result.
As for latex, you can keep the tex sources when compiling to pdf with the following option in your yaml front matter:
---
output:
pdf_document:
keep_tex: true
---

Jump to position in .Rnw file in PDF produced by knitr

I'm using knitr to convert .Rnw files to .pdf files. I can use Skim to jump from a position in the .pdf file to the .tex file produced by knitr.
How can I jump from a position in the .pdf file to the .Rnw?
Check out SyncTeX. For example, RStudio's PDF viewer provides a synchronization between the PDF and the underlying Rnw file, see here or here.

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

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
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.

How to convert .Rmd file to .Rnw file of Rstudio?

I really like using knitr in Rstudio and have been using it to write markdown presentations and data analysis. I want to use the same code and results in a paper and want to convert the code chunks in Rmd file ```{r} to the chunks of Rnw file << >>= #.
This allows using the same document and code written for presentation for the main paper as well.
Is there a way of converting between code chunks of markdown and Rnw files ?
or the entire file itself as apart from the difference in syntax of code chunks, they are quite similar in the markup (converting the text to latex is easy with say pandoc)
Instead of converting the whole document, you can just externalize your R code so it can be shared across different documents; see http://yihui.name/knitr/demo/externalization/
Once you have read_chunk('Rcode.r'), you can use ```{r label} in your Rmd and <<label>>= in your Rnw document, where label comes from the line ## #knitr label in the R script.

Resources