0

I created an empty R Markdown file, trying to convert it into a PDF file. I have installed the TinyTex package, but an error showed up:

output file: Test-File.knit.md

! ...sers\wjx\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:935: ...sers\wjx\AppData\Roaming\TinyTeX\bin\win32\runscript.tlu:858: no appropriate script or program found: fmtutil
! Running the command C:\Users\wjx\AppData\Roaming\TinyTeX\bin\win32\fmtutil-user.exe

! Running the command C:\Users\wjx\AppData\Roaming\TinyTeX\bin\win32\fmtutil-user.exe

! kpathsea: Running mktexfmt pdflatex.fmt

! The command name is C:\Users\wjx\AppData\Roaming\TinyTeX\bin\win32\mktexfmt

Error: LaTeX failed to compile Test-File.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Test-File.log for more info.
Execution halted

Before this error, I installed TinyTex package on R Studio, an error like below showed up :

> tinytex::install_tinytex()
trying URL 'https://yihui.org/tinytex/TinyTeX-1.zip'
Content type 'application/octet-stream' length 104721853 bytes (99.9 MB)
downloaded 99.9 MB

Error in extract(pkg, exdir = path.expand(target)) : 
  cannot open file 'C:/Users/wjx/AppData/Roaming/TinyTeX/bin/win32/ucrtbase.dll': Permission denied
> tinytex::reinstall_tinytex()
If reinstallation fails, try install_tinytex() again. Then install the following packages:

tinytex::tlmgr_install(c("The system cannot find the path specified."))

The system cannot find the path specified.
The system cannot find the path specified.
Error in extract(pkg, exdir = path.expand(target)) : 
  cannot open file 'C:/Users/wjx/AppData/Roaming/TinyTeX/bin/win32/ucrtbase.dll': Permission denied

By the error message, I have tried install_tinytex() again, but it didn't work. I have also consulted the post: Installing package - cannot open file - permission denied. I tried the first solution: run R Studio as an administrator, and install TinyTex. Here is the message in the instalation process:

> install.packages("tinytex")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/wjx/Documents/R/win-library/4.1’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.1/tinytex_0.36.zip'
Content type 'application/zip' length 129074 bytes (126 KB)
downloaded 126 KB

package ‘tinytex’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\wjx\AppData\Local\Temp\RtmpIREM3V\downloaded_packages

So I installed Rtools by following the URL listed in the error message, but from then on, the error at the beginning of the post showed up every time I knit my R Markdown file to PDF.

Phil
  • 7,287
  • 3
  • 36
  • 66

1 Answers1

0

I helped a friend fix a similar problem, and you may be lucky to get a fix too if you have a latex distribution installed on your computer. Here is what I did after trying several options to no avail:

I configured the RMarkdown document (by declaring "keep_tex: true" in the YAML metadata as shown below) to generate the latex codes and run the resulting tex file in TeXstudio. While the tex file was being compiled, I was prompted to install missing packages which I did through TeXstudio by simply clicking the install button from the prompt dialogue box. In the end, the file was able to compile successfully to pdf in the TeXstudio. I then went back to RStudio to knit the markdown file to pdf and bingo! - it knitted without errors.

Hope this helps!

---
title: "Untitled"
author: "William Agyapong"
date: "8/27/2022"
output: 
  pdf_document:
    keep_tex: true
---