Using knit2pdf with rmd files

Is it possible to use the knitr2pdf () function directly with R Markdown (Rmd) files? I have seen various textbooks / class notes, which apparently suggest that it could be, for example, here and here (Ctrl + F "knit2pdf").

But when I take a simple rmd file (saved as "test.rmd")

--- title: "knit2pdf test" author: "A Aaronson" date: "Thursday, February 19, 2015" output: pdf_document --- This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: ```{r} summary(cars) ``` You can also embed plots, for example: ```{r, echo=FALSE} plot(cars) ``` Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. 

and try

 library(knitr) knit2pdf("test.Rmd") 

I get the following error

leads to:

 output file: test.md Error: running 'texi2dvi' on 'test.md' failed LaTeX errors: ! Emergency stop *** (job aborted, no legal \end found) ! ==> Fatal error occurred, no output PDF file produced! ! ==> Fatal error occurred, no output PDF file produced! In addition: Warning message: running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf "test.md" --max-iterations=20 -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/tex/latex" -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/bibtex/bst"' had status 1 

Clicking the Knit PDF button always successfully creates a PDF file. So, did I skip the intermediate step?

I have to add that knit2pdf () with Rnw files works as expected for me, although I still get a warning

 running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf "rnwtest.tex" --max-iterations=20 -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/tex/latex" -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/bibtex/bst"' had status 1 

Help with thanks.

+8
r knitr r-markdown
source share
1 answer

Your input file is in rmarkdown format.

You must use the render() function in the rmarkdown package to compile your document.

Try:

 library("rmarkdown") render("temp.rmd") 

enter image description here

+7
source share

All Articles