R-Forge Logo

T-LoCoH - Installing rgeos and rgdal on a Mac


The rgeos package contains functions to union polygons together (amongst others), and is a dependent (i.e. required) package for T-LoCoH. rdgal is a suggested package, because it contains functions for importing GIS data (which can be displayed in plots).

If you are using OS X Mavericks or later, there may not be binary versions of rgeos or rdgal on CRAN. This means you have to install the geos and gdal libraries separately (free), and then install the rgeos and rgdal R packages (from source). The steps below describe that process in more detail.

Steps for installing geos and rgeos

These instructions were adapted from Lost in Geospace.

  1. Download and install the GDAL Complete frameworks (which includes gdal and geos) for MacOS X from http://www.kyngchaos.com/software:frameworks
  2. Problems installing geos? You can also install geos using MacPorts, which is a Mac utility you can download that allows you to install open source software using a command line (in Terminal). MacPorts example.

You've now installed geos. If fortune is smiling on you, you may just be able to install rgeos by typing in R:

install.packages("rgeos", repos="http://R-Forge.R-project.org", type="source")

If that worked, then you're done. But, if you get an error message, the next thing to try is to install rgeos from the command line.

  1. Make sure you're logged into your Mac with an administrator acount.
  2. Download the latest source package of rgeos from https://r-forge.r-project.org/R/?group_id=602 (click the "Package source (.tar.gz)" link). You should see a *.tar.gz file in your downloads folder. Do not decompress the file (i.e. make it a folder). If Safari automatically decompressed it without asking you, try to ctrl+click on the link and save it to your downloads folder.
  3. Open Terminal on your Mac (its usually found in Applications --> Utilities). Type the following command (modified as described below) in Terminal:
    R CMD INSTALL /path-to-rgeos/rgeos_version.tar.gz --configure-args='--with-geos-config=/Library/Frameworks/GEOS.framework/unix/bin/geos-config'
  4. If it worked, you should see some compiling going on, ending with:

    ** R
    ** inst
    ** preparing package for lazy loading
    ** help
    *** installing help indices
    ** building package indices ...
    ** testing if installed package can be loaded
    * DONE (rgeos)
  5. See if it worked by typing into R:


Steps for installing gdal and rgdal

The steps for installing gdal and rgdal are very similar to the ones above. Remember that rgdal is only needed if you plan on displaying GIS files in your plots.

  1. If you didn't already do it above, download and install the GDAL Complete frameworks for MacOS X from http://www.kyngchaos.com/software:frameworks.

    Problems installing gdal? You can also install gdal using MacPorts, which is a Mac utility you can download that allows you to install open source software using a command line (in Terminal). MacPorts example.

  2. Attempt to install rgdal in R with the command:
    install.packages("rgdal", repos="http://R-Forge.R-project.org", type="source")
  3. If that didn't work, type the following command (modifying the paths as needed, see above) in Terminal:
    R CMD INSTALL /path-to-downloads/rgdal_0.9-1.tar.gz --configure-args='--with-gdal-config=/Library/Frameworks/GDAL.framework/Programs/gdal-config

Option of last resort

If installing from source didn't work, some nice person at the University of Oxford has created Mac binaries for rgeos and rgdal. Note though these may not by the most recent versions of the packages, and they may or may not work with the most recent version of R.


Questions? Comments? Alternative solutions? Please email the package author.