Building R packages: missing path to pdflatex

December 15, 2012

(This article was first published on Daniel J. Hocking » Blog, and kindly contributed to R-bloggers)

Recently whiling trying to build an R package for generalized estimating equation model selection (QICpack on github), I was getting an error related to latex creating the PDF package manuals. It seems like this is a relatively common problem on some versions of Mac OS X, but I did not find it easy to find an answer so I thought I’d describe my ultimate solution.

The specific error I was getting was:

error in texi2dvi(file = file, pdf = true, clean = clean, quiet = quiet, : 
pdflatex is not available

I was getting this error regardless of whether building the package using R CMD packagename in the Terminal or using build in R or Rstudio via the devtools package.

I tried reinstalling MacTex and restarting my computer to no avail. It turned out that it was a problem with not having a path to the Tex installation. You can check using the following code in the Terminal or in R:


In my case, I got something like:





I don’t know much about setting paths, profiles, and environments, but this indicated that there is no path to latex and so the build function can’t find pdflatex needed to convert the .Rd files (LaTeX code of manuals in R packages) to PDF files for the R package. I was able to fix the problem by adding a path to the latex binaries using:


Now when I run Sys.getenv("PATH") I get


Now R is able to find the LaTeX binaries and when I run Sys.which("pdflatex") I get


That should fix the problem and now the build function can turn the .Rd files into PDF documents of the R functions.

Filed under: R Tagged: Error, LaTeX, mactex, packages, pdflatex, R

To leave a comment for the author, please follow the link and comment on their blog: Daniel J. Hocking » Blog. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)