What commands are run when the "Compile PDF" button is clicked?


#1

Hi,
I am not clear what commands R-Studio runs when the "Compile PDF" button is clicked.

I am using Sweave and a Rnw file to produce a PDF. Using R studio, when I click the "Compile PDF" button the Rnw file is processed and the PDF is displayed (My local version of R-Studio is configured to use knitr, "pdflatex" to compile the files and the system viewer to display the compiled PDF).

However, I cannot do the same things in an R script.
I have run this command:
Sweave("template.Rnw")
and gotten a message that a tex file has been written. I don't know how to compile this tex file within R.

When I try
knit2pdf("template.Rnw")
I get the following error:
output file: template.tex

Error: Failed to compile template.tex.
In addition: Warning message:
running command '"pdflatex" -halt-on-error -interaction=batchmode "template.tex"' had status 1

So, how do I replicate the commands run by the "Compile PDF" button in an R script?

TIA
AB


#2

What do you get if you run system("pdflatex template.tex")? Are you on Windows? What's your TeX distribution?


#3

I figured the commands out:
knit("template.Rnw") # created the tex file
tools::texi2pdf("template.tex") # creates the pdf
system('open "template.pdf"') #displays the pdf, once displayed the adobe pdf viewer give users the option to save.

I'll integrate this into my shiny app and things should be okay.

Right now, I'm running windows 7 with miktex 2.9 profiding the pdfLatex instance. In production, this will move to a docker container on out server.

Cheers
AB