R knit to PDF not working properly with errors

I am trying to knit a document to pdf. I can knit to HTML just fine, but the pdf never works. Things I have tried:

  • Update all packages
  • install.packages("tinytex")
    • installs perfectly and shows in in the packages pane
  • tinytex::install_prebuilt()
tlmgr conf auxtrees add "C:/PROGRA~1/R/R-4.0.3/share/texmf"
Error in system2("tlmgr", args, ...) : 
  'CreateProcess' failed to run 'C:\Users\XXX XXX\AppData\Roaming\TinyTeX\bin\win32\tlmgr.bat info --list --only-installed --data name'
  • tinytex:::install_tinytex()
Error in system2("tlmgr", args, ...) : 
  'CreateProcess' failed to run 'C:\Users\XXX XXX\AppData\Roaming\TinyTeX\bin\win32\tlmgr.bat info --list --only-installed --data name'
  • knit button
Error in system2("tlmgr", args, ...) : 
  'CreateProcess' failed to run 'C:\Users\XXX XXX\AppData\Roaming\TinyTeX\bin\win32\tlmgr.bat update --all --self'
Calls: <Anonymous> ... latexmk_emu -> run_engine -> system2_quiet -> tlmgr_update
In addition: Warning message:
In system2(..., stdout = if (use_file_stdout()) f1 else FALSE, stderr = f2) :
  'CreateProcess' failed to run 'C:\Users\XXX XXX\AppData\Roaming\TinyTeX\bin\win32\pdflatex.exe -halt-on-error -interaction=batchmode "Document.tex"'
Execution halted
  • Complete uninstall and reinstall of R and RStudio

I'm at a loss at this point and nothing I have found online has worked. It is clear that I am completely unable to install tinytex but I am unsure why. Possibly it is because I have a space in my username on my laptop, however I do not know how to bypass that.

Metadata sections:

Without xelatex

---
title: "A Document"
output: pdf_document
---
Error in system2("tlmgr", args, ...) : 
  'CreateProcess' failed to run 'C:\Users\XXX XXX\AppData\Roaming\TinyTeX\bin\win32\tlmgr.bat update --all --self'
Calls: <Anonymous> ... latexmk_emu -> run_engine -> system2_quiet -> tlmgr_update
In addition: Warning message:
In system2(..., stdout = if (use_file_stdout()) f1 else FALSE, stderr = f2) :
  'CreateProcess' failed to run 'C:\Users\XXX XXX\AppData\Roaming\TinyTeX\bin\win32\pdflatex.exe -halt-on-error -interaction=batchmode "Document.tex"'
Execution halted

With xelatex

---
title: "A Document"
output:
   pdf_document:
     latex_engine: xelatex
---
Error in system2("tlmgr", args, ...) : 
  'CreateProcess' failed to run 'C:\Users\XXX XXX\AppData\Roaming\TinyTeX\bin\win32\tlmgr.bat update --all --self'
Calls: <Anonymous> ... latexmk_emu -> run_engine -> system2_quiet -> tlmgr_update
In addition: Warning message:
In system2(..., stdout = if (use_file_stdout()) f1 else FALSE, stderr = f2) :
  'CreateProcess' failed to run 'C:\Users\XXX XXX\AppData\Roaming\TinyTeX\bin\win32\xelatex.exe -halt-on-error -interaction=batchmode "xelatex.tex"'
Execution halted

I believe this is a very annoying issue because you may have a space in your Windows username.
There are other issues like that in this community, for example : Failed to run c:/..../pdflatex.exe

There is not a clear fix yet because the source is not well known yet.
You may try to add the directory C:\Users\XXX XXX\AppData\Roaming\TinyTeX\bin\win32 in PATH but I am not sure that will do the trick.

This was the issue. I went to a different user that didn't contain spaces and the PDF converted without errors.

1 Like

I am also interested in this issue as I have been having problems and also have a space in my name. @cderv can Miktex replace Tinytext as a solution?

hi @escully I finished setting up miktext and it seems to work even though my username has a space. I can produce a PDF fine. Hope that helps you.

Hi @blue,

thanks for testing this !

I have a few question so that we isolate the issue to fix it:

If you are an R user, you can install the R package tinytex , and pass a custom directory name to the dir argument of tinytex::install_tinytex() .

If that does not work, that would mean this is something in Tex Live, but I don't think so.

Could you try ? Thanks !

@cderv I could not get TinyTeX to work by moving it to a different location. I tried following the steps indicated on the website and also did external searches which came up short. RStudio would never recognize the place where I moved TinyTeX to (my C: drive). I'm not saying it's impossible, I just couldn't figure it out.

MikTeX works for me now that I have it downloaded in a folder with no spaces. Thanks blue!! A note for anyone who finds this in the future, when I initially knitted the pdf in R, MikTeX prompted that I needed to install some packages. I accepted each one but after it was done R gave me an error that MikTeX had issues and it logged it in a file on the computer. After checking the log, things went downhill starting at FATAL pdflatex - GUI framework cannot be initialized. After looking into this, apparently RStudio can get confused by the package loader for MikTeX and prematurely stop loading the packages, meaning that when it runs, all of the necessary packages have not yet been loaded. To bypass this and also figure out what packages I needed, I found the .tex file the R had created (in the same folder as the .rmd file I was trying to knit) and ran that in TeXworks. TeXworks promted me to install many more packages and eventually compiled my PDF. After that, I went back to RStudio, knitted to PDF, and it worked perfectly.

1 Like

That is too bad. It should have worked. There must be something to fix in the installation process.
What you could do if you want to stay TinyTeX is to set an option to indicate where to find the installation folder.

options(tinytex.tlmgr.path = "C:/TinyTeX/bin/win32/tlmgr.bat")

If you put that in your Rprofile, it will be available to all R sessions

usethis::edit_r_profile()

I must precise that after you installed TinyTeX, it should have been put into the PATH. You may have to restart your computer after installation. I correctly see in the PATH on my computer after having installed TinyTeX using

tinytex::install_tinytex(dir = "C:/TinyTeX")

This worked! I was using the command line to set the tlmgr path and must not have been doing it properly. After running options(tinytex.tlmgr.path = "C:/TinyTeX/bin/win32/tlmgr.bat") it worked great. Thanks for the help!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.