25

I am trying to build a package in R. I made the skeleton, and ran the command R CMD check package1. I got an an error described here. I followed the solution steps, and the results are:

  1. package devtools not available for R 2.15.1

  2. punched in R CMD Rd2pdf package1.

Hmm.. Looks like a package
Converting Rd files to LaTeX
Creating pdf output from LaTeX
Error in texi2dvi(file=file, pdf=true, clean=clean, quiet=quiet, : pdflatex not available
Error in running tools::texi2pdf
  1. I looked up this amongst other things, installed the complete tex live & MiKTeX. Same error message showed up.
  2. I navigated to the directory where pdflatex is located and tried running the command from there. Didn't help.

Is there something I'm missing here, or is there a workaround? Or maybe, Is there a way to suppress pdf generation during package creation?

UPDATE: This error was not thrown when I tried it in LINUX (CentOS).

Community
  • 1
  • 1
jackStinger
  • 2,035
  • 5
  • 23
  • 36

6 Answers6

24

you certainly can suppress the PDF generation.

R CMD check package --no-manual

From here

Oliver Shaw
  • 5,235
  • 4
  • 26
  • 35
4

Step 1: Download and Install MiKTeX from http://miktex.org/2.9/setup

Step 2: Run

Sys.getenv("PATH") 

in R studio This command returns the path where Rstudio is trying to find pdflatex.exe In windows (64-bit) it should return C:\Program Files\MiKTeX 2.9\miktex\bin\x64\pdflatex.exe If pdflatex.exe is not located in this location Rstudio gives this error code 41.

Step 3: To set this path variable run:

Sys.setenv(PATH=paste(Sys.getenv("PATH"),"C:/Program Files/MiKTeX 2.9/miktex/bin/x64/",sep=";"))
Scott Grammilo
  • 1,229
  • 4
  • 16
  • 37
  • Thanks, with the last miktex version (20.6.29-) for me this was `Sys.setenv(PATH=paste(Sys.getenv("PATH"),"C:/Users/MY_USER_NAME/AppData/Local/Programs/MiKTeX/miktex/bin/x64",sep=";"))` – moodymudskipper Aug 19 '20 at 16:43
3

Although you have installed MikTeX under Windows, this does not make it available to R. You need to add the location of the latex executables to your PATH environment variable. How to do this exactly depends on your Windows version. For example, this link describes how to do this for Windows 7. Googling for change environment variables (windows 7|windows xp|windows 95) will tell you how to change your environment variables.

Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149
1

Just follow this video's instructions to install MikTex on windows:

https://www.youtube.com/watch?v=k-xSGZ-RLBU

I also had similar problems about pdfLatex Not Available. After installing MikTex this way, errors like "pandoc.exe: pdflatex not found. pdflatex is needed for pdf output. Error: pandoc document conversion failed with error 41" can be solved when creating pdf using knitr.

The installation file can be downloaded from:

http://mirrors.ctan.org/systems/win32/protext/ProTeXt-3.1.5-033015.exe

Tom
  • 3,168
  • 5
  • 27
  • 36
1

I recently got the same issue. For me, what worked was to install texlive-fonts-extra. This works for the Docker R-base image and also for Ubuntu.

In CentOS the package system is different, and you might need to install a higher number of latex-related packages (example here).

elcortegano
  • 2,444
  • 11
  • 40
  • 58
  • 1
    This solution worked for me on Ubuntu 20.04 and R 4.0.3. I used the following command: `sudo apt install texlive-fonts-extra` – epo3 Jan 05 '21 at 17:08
0

On MacOS I got this to work by running the following in the termina:

brew install basictex
Oscar Kjell
  • 1,599
  • 10
  • 32