Rmarkdown::render complains pdflatex had status 1 when processing a very simple Rmd file

I have a very simple test.Rmd file:

---
title: "test"
output: pdf_document 
---

done.

This is what I get after render:

rmarkdown::render("test.Rmd")

processing file: test.Rmd
|.................................................................| 100%
ordinary text without R code

output file: test.knit.md

"C:/PROGRA~2/Pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.tex --template "C:\Users\username\Documents\R\win-library\3.4\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --pdf-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"
Error: Failed to compile test.tex.
In addition: Warning message:
running command '"pdflatex" -halt-on-error -interaction=batchmode "test.tex"' had status 1

I could see that only test.tex file was created. Also:

  1. When I run pdflatex using the same command in console, it worked fine and created the PDF:

system('"pdflatex" -halt-on-error -interaction=batchmode "test.tex"')
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (MiKTeX 2.9.6630 64-bit)
entering extended mode

  1. If I don't run rmarkdown::render but instead use the "Knit" button in RStudio, the PDF was also produced just fine.

I'm using RStudio 1.1.419, rmarkdown 1.9.5, knitr 1.20, pdfTex and MikTex versions see above, and everything was run on Windows 10.

I searched web a lot but didn't see anything that'd help. I put the Rmd file in a path that had no space or any weird char, reinstalled MiKTex and pdflatex required packages, tried disable or enable shell escape commands, same error message every time.

Thanks!

Did you ever find a solution to this?I did the same thing and I am having the same issue (slightly different error message). Knit buttom works fine.

rmarkdown::render gives me the following error:

output file: test.knit.md

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template "C:\Users\shkacink\Documents\R\R-3.4.3\library\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"
pandoc.exe: pdflatex not found. pdflatex is needed for pdf output.
Error: pandoc document conversion failed with error 41
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template "C:\Users\shkacink\Documents\R\R-3.4.3\library\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"' had status 41

Try installing tinytex package?