6

Reproducible example (if you have rstudio):

  • File | New | R Markdown
  • Knit to html, saving as test :

knitr

Navigate to working directory

  • In a terminal (with pandoc installed) type

    pandoc -s test.md -t latex -o test.tex

(results pasted here)

  • Convert to pdf with pdflatex (see result here)

Or skip the tex stage by going directly to .pdf:

pandoc -s test.md -t latex -o test2.pdf

The results are good, but seem like a lot of steps given that knitr incorporates sweave. It should be able to convert from .Rmd to .tex or .pdf directly. Right?

RobinLovelace
  • 4,799
  • 6
  • 29
  • 40
  • 1
    Of course "is it possible". Has something written such a new converter which skips one or more steps of an existing tool pipeline? Unsure, to unlikely. – Dirk Eddelbuettel Jan 04 '13 at 15:50
  • Thanks for this - maybe a feature request for RStudio developers: add a "knit to LaTeX" button to reduce fiddle. Seems compatible with their philosophy http://www.rstudio.com/training/philosophy.html – RobinLovelace Jan 04 '13 at 15:56

2 Answers2

11

This is documented in http://www.rstudio.com/ide/docs/authoring/markdown_custom_rendering; you should add an .Rprofile to your directory, for example:

options(rstudio.markdownToHTML = 
  function(inputFile, outputFile) {      
    system(paste("pandoc", shQuote(inputFile), "-o", shQuote(outputFile)))
  }
)  

Some modifications might be necessary. Too bad the same does not work with spin because of a bug in RStudio.

http://support.rstudio.org/help/discussions/problems/4128-spin-and-rprofile

Dieter Menne
  • 10,076
  • 44
  • 67
  • 7
    this is a nice answer. It seems to do what the OP wanted, although it's not technically "without pandoc" (e.g. if someone who hadn't/couldn't install[ed] pandoc wanted to do this), rather it's "without an additional annoying manual invocation of pandoc". – Ben Bolker Jan 04 '13 at 16:18
1

For anyone who stumbles upon this old question, there is now (has been for a while) a keep_tex: true parameter that preserves the intermediate .tex file created by Pandoc. Call it like this in the YAML header:

---
output:
  pdf_document:
    keep_tex: true
---
Robert McDonald
  • 1,250
  • 1
  • 12
  • 20