From Markdown to LaTeX output using RMarkdown.

[This article was first published on Learning Slowly » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I’ve been working on the ggRandomForests vignettes pretty consistently now. I’m writing the randomForestSRC-Survival vignette in LaTeX with the knitr vignette engine. I wrote the the randomForestSRC-Regression vignette in markdown.

I’ve decided to upload the Regression vignette to arXiv for additional distribution. The arXiv submission process prefers LaTeX files, and since RMarkdown can compile to pdf, using pandoc through a LaTeX document, I was hoping for a simple way to go from Markdown to LaTeX. My idea was to generate the LaTeX source, and do a few cleanup edits before submitting.

I tried a few things, Rstudio tends to remove the intermediate tex file after compile. So I went to the rmarkdown::render command. The intermediate files were still removed.

Then I found the presentation at http://blog.rstudio.org/2014/06/18/r-markdown-v2/. The “Aha!” moment was when Yuhui said that the yaml metadata commands pdf_document, html_document and word_document are commands within the RMarkdown package. A quick help search:

> ?pdf_document

pdf_document(toc = FALSE, toc_depth = 2, number_sections = FALSE,
  fig_width = 6.5, fig_height = 4.5, fig_crop = TRUE,
  fig_caption = FALSE, highlight = "default", template = "default",
  keep_tex = FALSE, latex_engine = "pdflatex", includes = NULL,
  pandoc_args = NULL)

and there is a keep_tex argument. Suddenly, the rest of the yaml markdown syntax also makes sense.

I changed my output syntax from:

output:
  pdf_document: 
    fig_caption: true

to:

output:
  pdf_document: 
    fig_caption: true
    keep_tex: true

The Rstudio knit PDF button still removes the tex file, but using the command line render command works as I need.

Now I just need to add a few edits… and I’m off!


Filed under: R Tagged: ggRandomForests, knitr, R, rmarkdown, yaml

To leave a comment for the author, please follow the link and comment on their blog: Learning Slowly » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)