Unable to knit to pdf in R markdown

Hello, could someone please help me. I have been getting this error when trying to knit to pdf in r markdown

Error: LaTeX failed to compile CV-EXAMPLE.tex. See The R package tinytex - Helper Functions to Manage TinyTeX, and Compile LaTeX Documents - Yihui Xie | 谢益辉 for debugging tips.
In addition: Warning message:
In system2(..., stdout = if (use_file_stdout()) f1 else FALSE, stderr = f2) :
'"pdflatex"' not found
Execution halted

Hi @IfeoluwaDavid,

What operating system are you using? Windows? Mac?

Have you ever installed a TeX distribution?

What do you get when you run this in R?

Sys.which('pdflatex')

I use a Windows operating system. When I ran the code, it showed this:
pdflatex
""

Okay, so this indicates you either don't have pdflatex installed, or it can't be found. If you've never installed a TeX distribution, then the former is probably true.

My recommendation is to use the {tinytex} package and use it to install a lightweight but fully-functional TeX distribution.

You can run this code in R:

tinytex::install_tinytex()

This may take several minutes to install. Once complete, reset your R session and try running Sys.which('pdflatex'). This time it should show you the path to pdflatex which means you should be good to go.

Try rendering the Rmd to PDF and it should work.

2 Likes

When I ran this code:
tinytex::install_tinytex()
It showed this :
Error in system2("tlmgr", args, ...) : '"tlmgr"' not found
In addition: Warning message:
In extract(pkg, exdir = path.expand(target)) :
error 1 in extracting from zip file

Hmm, there seem to be other threads about getting TinyTeX installed on a Windows machine. I am not a Windows user so I don't know that I can be helpful. Here are some threads that may have possible solutions for you:

Also, perhaps if we are lucky @cderv will appear. He is a wizard with these things.

Oh, thanks a lot. I'll try them out and let you know once I have gotten it

tinytex::install_tinytex()

this should be the command to run. Can you share all the outputs you get when running this command ? I am surprised that Error in system2("tlmgr", args, ...) : '"tlmgr"' not found would be the direct printed log you get :thinking:

It showed this :

tinytex::install_tinytex()
trying URL 'https://yihui.org/tinytex/TinyTeX-1.zip'
Content type 'application/octet-stream' length 106251731 bytes (101.3 MB)
downloaded 172 KB

Error in system2("tlmgr", args, ...) : '"tlmgr"' not found
In addition: Warning message:
In extract(pkg, exdir = path.expand(target)) :
error 1 in extracting from zip file

When I tried it again it kept showing this code:

Error in system2("tlmgr", args, ...) : '"tlmgr"' not found
In addition: Warning message:
In extract(pkg, exdir = path.expand(target)) :
error 1 in extracting from zip file

Ok the issue is because of this above. The downloaded zip was not extracted correctly and this made the installation broken.

Do you have writable access to your computer or are you in a lock environment ?

I don't know the difference between the 2 environments, so I can't I really say for sure which environment I'm in. Could you please explain ?

I mean do you think you could encounter some writing access issue on your computer ?
It seems that unzipping the bundle is not working for you when R is trying to do so.

Other options to install TinyTex can be found here

@cderv and @mattwarkentin Thank you so much. The code finally ran. I guessed it didn't work earlier because of the internet issues

tinytex::install_tinytex()

3 Likes

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.