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.
JAGS is an alternative to BUGS (WinBUGS or OpenBUGS) for conducting a Bayesian Analysis. It stands for Just Another Gibbs Sampler, and like WinBUGS, it is essentially an MCMC machine that employs a Gibbs sampler so you don’t have to write your own for every analysis. JAGS code is very similar to the more popular BUGS so it is an easy transition. JAGS has the advantage of running on multiple platforms (Windows, Mac, Linux). It is also open source and based in C++ so it will likely have more continued development than the more well established BUGS software. Unlike WinBUGS, JAGS has no user interface and you will not see it in your Programs/Applications folder. It has to be run from another program, most commonly R using rjags. R2JAGS is an R wrapper for JAGS and rjags that provides some additional features.
I have not yet updated my operating system or all of my software, and as such, I’ve had some difficulty installing and running JAGS/rjags. I finally got it working after two long days and thought I’d post my solution in case anyone finds themselves in the same situation. Hopefully when I do update to Snow Leopard in the next month I don’t have any problems just using the most up to date versions. For now, here is a solution using:
Mac OS 10.5.8
2. From the same site download the rjags_2.2.0-1.tar.gz file to your desktop
3. Install the rjags package. I tried install.packages(‘/Users/Dan/Desktop/rjags_2.2.0-1.tar.gz’, repos = NULL, type = “source”) and it seemed to work, but when I typed library(rjags) I got the following error message:
Error: package ‘rjags’ is not installed for ‘arch=x86_64’
4. If that happens, I found that installing from the Terminal with additional instructions worked like a charm. If like me you are not experienced with the Mac Terminal and command line entry, I will provide explicit instructions that I found:
- Open Terminal (/Applications/Utilities/Terminal.app)
- Navigate to where you downloaded the source package. In my case the desktop, so I typed, “cd /Users/Dan/Desktop/” (without the quotes). You should notice that the cursor is now indicating that directory.
- Now that it knows where to find the file, have the Terminal tell R to install the package as a 64-bit version by typing the following into the Terminal: R –arch x86_64 CMD INSTALL rjags_2.2.0-1.tar.gz
5. Open R64 back up and rjags should be installed. Load the library with “library(rjags)” and it should work. At least it worked for me. Good luck!