简体   繁体   中英

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.

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

The issue was with my file path having a space in it. I went to a different user on my computer which didn't have any spaces and the file converted to a PDF just fine.

Step 1: To fix this issue, go to Tools ---> Global Options ---> Sweave in R Studio.

  • Then under Typeset LaTex into PDF using select XeLaTex .
  • Under LaTex Editing and Compilation , tick "Use tinytex when compiling.tex files.
  • Click Apply and Ok .

Step 2: In R Markdown, install tinytex in an R chunk

```{r}
tinytex::install_tinytex(force = TRUE)
library(tinytex)

Step 3: In the header block, type the output as:

output:
  pdf_document:
    latex_engine: xelatex

Select the Knit to PDF and your document should knit correctly.

If any of these help, kindly upvote it so more people can see the solution that worked. Cheers!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM