rrstudiopdflatexsweavemiktex

RStudio Sweave error -> exit code -1073740791


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.


Solution

  • 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 real answer, of course, is for RStudio to correctly deal with the "--version" response but this is working for me now.

    Rich