Site icon R-bloggers

Installing rgdal on Mac OS X

[This article was first published on Spatial Analysis » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.


After running a spatial data analysis with R session today, it became apparent that there are one or two teething problems installing the important rgdal package on Mac OS X operating systems. The usual install.packages(“rgdal”) won’t work. My colleague Jon Reades did some digging around to find this solution. I have tested it and it seems to work fine.

[Note that you’ll need to be comfortable with the Terminal. If you’re not, then find someone who is.]

1. Download the GDAL OS X install from kyngchaos
http://www.kyngchaos.com/files/software/unixport/GDAL_Complete-1.7.dmg
(Looks like the basic page [for updates after 1.7 if you’re reading this ages from now] is http://www.kyngchaos.com/software/frameworks)
– Install as per usual OS X install system
– Fire up the Terminal, then pico (or vi[m]) the .bash_login file
– Modify the PATH environment so that it reads:
export PATH=”/Library/Frameworks/GDAL.framework/Programs:$PATH”
[This is what enables the subsequent steps to find gdal-config]

2. Download and install proj4 from source
http://trac.osgeo.org/proj/wiki/WikiStart#Download
– Download source code version proj-4.7.0.tar.gz
– Fire up the Terminal
> cd ~/Downloads/
> tar -xzvf proj-4.7.0.tar.gz
> cd proj-4.7.0
> ./configure
> make && make test
> sudo make install
[ should install to /usr/local/lib by default]

3. Download and install rgdal from source
http://cran.r-project.org/src/contrib/rgdal_0.6-28.tar.gz
– Fire up the Terminal
> cd ~/Downloads/
> sudo R CMD INSTALL –configure-args=’–with-proj-include=/usr/local/lib’ rgdal_0.6-28.tar.gz

After all of this mucking about I was able to say:

> require(sp)
> require(rgdal)

And get a message indicating that GDAL was loaded successfully.

He also posted his solution on the Computational Mathematics Blog. If there is a better way I would be interested in hearing about it for future classes.

To leave a comment for the author, please follow the link and comment on their blog: Spatial Analysis » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.