RStudio Sweave error -> exit code -1073740791

Viewed 2771

I have problem with running my .rnw (I am running Sweave) files in RStudio due to this error message:

Writing to file test.tex
Processing code chunks with options ...

You can now run (pdf)latex on 'test.tex'
Running pdflatex.exe on test.tex...failed
Error running C:/PROGRA~1/MiKTeX/miktex/bin/x64/pdflatex.exe (exit code -1073740791)

I have default instalation of MiKTeX and from what I see in my PC I downloaded version 21.2. I have been checking for updates and there aren't any new ones. I use freshly reinstaled Windows 10 as OS with freshly instaled R, RStudio and MiKTeX. So there should not be any interferance with another MiKTeX version.

When I check path to my MiKTeX in RStudio with this code: Sys.which("pdflatex") then I get this response:

                                              pdflatex 
"C:\\PROGRA~1\\MiKTeX\\miktex\\bin\\x64\\pdflatex.exe" 

I have also tried enabling shell escape commands in Tools/Global Options but this did not work also. I have no idea what could be wrong here. Do you have any idea how to fix this issue?

Thank you for your time and effort.

2 Answers

I too had this problem after updating MikTex and RStudio.

The pdflatex log showed that RStudio first calls pdflatex --version and then the error occurs. I concluded that RStudio didn't like the answer.

Edit 2:

So far, this seems correct and I have updated both MikTex and RStudio to the latest versions.

I would guess that installing an older version of MikTex works because the older pdflatex returns a version message that RStudio knows how to deal with.

My solution is this:

  1. In your R directory create a file, pdflatex.cmd
  2. In the same directory create a file rs.cmd (or any other name you want)

These files are:

---------- pdflatex.cmd -----------

@echo off
if %1 == --version goto version

pdflatex.exe %1 %2 %3 %4 %5 %6 %7 %8 %9    
goto :eof

:version
echo MiKTeX-pdfTeX 4.8 (MiKTeX 21.10)

----------- pdflatex.cmd -------------

The version returned is the first line of the output of "pdflatex --version"

----------- rs.cmd -------------

@echo off

rem Start RStudio with specific environment variables    
set RSTUDIO_PDFLATEX=pdflatex.cmd    
set PATH=%PATH%;"C:\Program Files\RStudio\bin\";..
start /D "C:\Program Files\RStudio\" rstudio.exe

----------- rs.cmd -------------

To use it, start RStudio with the rs command.

Now, clicking the 'Compile PDF' button successfully runs and compiles the pdf and opens it in the viewer.

There are some limitations:

  • The previous project environment is not completely restored; you may have to re-open some files.
  • The output of the pdflatex command is not captured by RStudio. If you have latex errors you may have to run pdflatex in a command shell to inspect them.

The real answer, of course, is for RStudio to correctly deal with the "--version" response but this is working for me now.

Rich

I had the same problem and only solution that I came up was uninstalling MikTex and installing TinyTex.

tinytex::install_tinytex()
Related