I'm trying to compile a simple Rnw file in Rstudio using knitr "compile pdf" functionality. But it gives me an error.

This is what I have in hello.Rnw:



Hello World



Running pdflatex.exe on hello.tex...failed

Error running C:/PROGRA~1/MIKTEX~1.9/miktex/bin/x64/pdflatex.exe (exit code 1)

However if I typeset hello.tex using TeXworks, it generates a pdf file without any error. I checked my Sys.getenv("PATH") variable, and it shows the correct MiKTeX location. So I'm not sure why RStudio pdflatex is not working.

C:\\Program Files\\1E\\NomadBranch\\;
C:\\Program Files (x86)\\Microsoft Application Virtualization Client;
C:\\Program Files (x86)\\WebEx\\Productivity Tools;
C:\\Program Files\\TortoiseSVN\\bin;
C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64;
  • do you have a pdflatex.exe in C:\Program Files\MiKTeX 2.9\miktex\bin\x64 ? – David Carlisle May 2 '18 at 21:21
  • @David, Yes, I've verified that there is a pdflatex.exe file at this location. – Sunny Kanugo May 2 '18 at 22:07
  • @Fran, I'm not sure how it is going to MIKTEX~1.9 while there is no such version. I don't see any such version. I also tried rebooting the system but it didn't help. – Sunny Kanugo May 2 '18 at 22:09
  • @Fran That is an 8.3 filename: en.wikipedia.org/wiki/8.3_filename You should not interpret ~1 as literally ~1. – Yihui Xie May 3 '18 at 2:26
  • @YihuiXie Hahaha ...you are right. How I did not realize! The mistake is doubly silly because for a long time I was a DOS user before and after the onset of long names in Windows. Even today I hate names not limited to 8.3 characters in any OS, in part due to the problems that I had with the ~1 truncations. – Fran May 3 '18 at 9:39

So I figured out the problem. There were two MikTeX installations on my machine. And the R PATH variable was pointing to the wrong one. I simply followed the instructions from the below link and it resolved the issue. Thank you! https://stackoverflow.com/questions/33650869/how-can-i-set-the-latex-path-for-sweave-in-r

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.