Consider the following minimal RNW file (test.Rnw
):
\documentclass{article}
\begin{document}
<<>>=
plot(1)
@
\end{document}
Clicking the "Compile PDF" button in RStudio gives the following error message (and no PDF is being produced):
Running pdflatex.exe on test.tex...failed
Error running C:/Users/myname/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex.exe (exit code -1073740791)
I'm encountering this issue on 4 different machines and strongly suspect that it arises from the interplay of RStudio and MiKTeX:
- All machines run Windows 10 and had MiKTeX, R and RStudio in more-or-less recent versions installed.
- In this baseline scenario, "Compile PDF" used to work on all machines.
- As soon as I perform a full update of MiKTeX, the error quotes above occurs.
- Updating RStudio and R (including installed packages) to their latest versions has no effect.
- Completely re-installing RStudio and MiKTeX has no effect.
All this might sound like MiKTeX is the culprit, however:
- If I knit the RNW file to get
test.tex
and compile this TEX file from the command line (or TeXStudio), it compiles without issues. system2(command = "pdflatex.exe", args = "test.tex")
from within R also works. By the way,Sys.which("pdflatex")
points to"C:\\Users\\myname\\AppData\\Local\\Programs\\MiKTeX\\miktex\\bin\\x64\\pdflatex.exe"
, which is the correct path.- Even
knit2pdf("test.Rnw")
works flawlessly.
Only RStudio's "Compile PDF" button does not work. I also checked "C:\Users\myname\AppData\Local\MiKTeX\miktex\log\pdflatex.log"
. As far as I understand it, it shows no errors:
2021-03-19 17:14:01,791+0100 INFO pdflatex - this process (10020) started by 'rsession' with command line: C:/Users/myname/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex.exe --version
2021-03-19 17:14:01,799+0100 INFO pdflatex - allowing known shell commands
2021-03-19 17:14:01,809+0100 INFO pdflatex - this process (10020) finishes with exit code 0
By the way, producing PDF output from RMD files causes no issues, but I guess this is because pandoc
does not use the local LaTeX distribution.
I did try tinytex::install_tinytex()
and in fact, this solves the issue. However, I have no(t much) control over the affected machines and therefore must use MiKTeX. Therefore, resorting to TinyTeX is not an option.
Any help in identifying and solving this issue is highly appreciated!
Please let me know if I can provide any further debug information.