Computing

Latest Version of R on Mac OS X

The authoritative resource for R installation on Mac OS X is here: http://cran.r-project.org/bin/macosx/

Basic R Package Installation

For the vast majority of packages, installation and maintenance is easily accomplished from within R itself.

 # Install a package
 > **install.packages**("//pkgname//")
 # Upgrade any outdated packages
 > **update.packages**()
 # Rebuild packages after upgrading to a new minor version of R (e.g. 2.8 -> 2.9)
 > **update.packages**(checkBuilt=TRUE)`</code>`

##  Installation tips for R packages with external dependencies
Your mileage may vary with these tips depending on your version of OS X, your version of R, your system configuration settings, and previously installed applications.

####  rgdal: Bindings for the Geospatial Data Abstraction Library

1. If you don't already have it installed, you'll probably need the Xcode tools package that come bundled (but not installed by default) with OS X. It should be on your OS X installer disc if you have one, but can also be downloaded for free (after registering) [[http://developer.apple.com/technology/xcode.html|here]].

2. Now install GDAL, PROJ.4, and some additional libraries using [[http://www.kyngchaos.com/software:frameworks#gdal_complete|KyngChaos compatibility frameworks]]. After downloading and unpacking this file, simply double-click the 'pkg' installer icon to begin installation.

3. To make the GDAL and PROJ.4 tools available at the command line, use a text editor to open the file called *.bash_profile* (or create one if it doesn't exist) in your home directory. Then enter the following lines:
`<code>`
 export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH
 export PATH=/Library/Frameworks/PROJ.framework/Programs:$PATH`</code>`

Now confirm that everything is working as expected. Note that these PATH updates will not have taken effect in the existing Terminal window, so first open a new Terminal tab/window, then see if the gdal-config command works:
`<code>`
 $ gdal-config --version
 1.8.0
  1. Next, manually download the most recent ‘Package source’ tarball of the rgdal package from its CRAN page. As of 18-Jan-2012, the most recent version was rgdal_0.7-8.

  2. Make sure you have already installed the sp package, which is required by rgdal. If you haven’t, open an R session an install the package:

    install.packages(“sp”)</code>

    1. Finally, open a Terminal window, and use R’s command line installer to install the rgdal package that you downloaded before. You will need to supply the compiler with several extra bits of information, using the command below. Note that you may need to edit the path to the tarball if you downloaded it to a different place on your hard drive, and you may need to edit the version number if you downloaded a different version. <code> $ R CMD INSTALL ~/Downloads/rgdal_0.7-8.tar.gz
      –configure-args=’–with-proj-include=/Library/Frameworks/PROJ.framework/unix/include –with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib’

If everything went well, you should be able to open R and load the rgdal package:

> library("rgdal")
 Loading required package: sp
 Geospatial Data Abstraction Library extensions to R successfully loaded
 Loaded GDAL runtime: GDAL 1.8.0, released 2011/01/12
 Path to GDAL shared files: /Library/Frameworks/GDAL.framework/Versions/1.8/Resources/gdal
 Loaded PROJ.4 runtime: Rel. 4.7.1, 23 September 2009, [PJ_VERSION: 470]
 Path to PROJ.4 shared files: (autodetected)