How to install R packages from source on Mac OS X

July 31, 2010
By

(This article was first published on Computational Mathematics » R, and kindly contributed to R-bloggers)

In my last post about installing the rgdal R package on Mac OS X, I had apparently glossed over the last step of compiling the R package from source.  I hadn’t realized that Mac OS X actually doesn’t come default with the necessary software to do this.  Most times, prepackaged binaries work fine but occasionally, packages may not have a binary available or may need to be customized.  For example, in rgdal, where the default search paths are incorrect for the GDAL frameworks on Mac OS X.

In order to compile a package from the source code, you’ll need the package source (typically a .tar.gz file on Mac OS X) and a compiler (e.g. gcc).  In my opinion, the easiest way to set up the necessary tools is to install Xcode from the Apple Developer site. You’ll need to register (free) for an Apple Developer Connection account to access the download.
(Update, May 20, 2011: Since version 4, Xcode is no longer free for non-developers but can be purchased for $4.99 from the Mac App Store. Xcode 3 remains free from the Apple Developer site and is sufficient if you just need the compilers installed).

Once Xcode has been installed, you’ll then have all the required tools to compile R packages from source.  To do so, simply navigate in Terminal to the folder you saved the source to (the .tar.gz file), and run:

R CMD INSTALL packagename.tar.gz

or some variety of the above with any custom configurations. The R command will automatically run the appropriate commands to compile the package. Happy compiling!

To leave a comment for the author, please follow the link and comment on his blog: Computational Mathematics » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: 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.