Computational Mathematics

Adventures in Computing, Statistics, and R

R and RStudio incompatibility with Yosemite Mac OS X 10.10


There is currently a bug (or feature?) in the current version of Yosemite (OS X 10.10) that messes with the passing of environmental variables to programs launched from Finder (as pointed out by Adam Maxwell).

Notably, this means that PATH variables are not passed properly to or You may end up seeing errors such as the following:

Error in system("pdflatex", intern = TRUE) : error in running command
sh: pdflatex: command not found

Error in system("convert", intern = TRUE) : error in running command
sh: convert: command not found

Until Apple releases a fix to this, the easy workaround is to launch the desired application from the command-line (terminal).

For example to launch R, you can instead run


And for RStudio, you can run


Let’s hope Apple releases a fix soon.

R with Vim on Mac OS X


The built-in script editor for the Mac OS X R GUI actually isn’t bad. In fact it is much better than its Window’s counterpart. In particular, it has:

  • Syntax highlighting
  • Auto-completion
  • Bracket matching
  • Auto-indent
  • Block code execution (with blocked command history)

However, when coding in R and pretty much any other language, Vim has always been my goto text editor of choice. Once you get past the fairly steep learning curve, nothing comes close to it in terms of coding efficiency and navigation except perhaps Emacs, but let’s not go there.

Michael Bojanowski wrote a blog post on using R with Vim on an Ubuntu machine. One commenter asked about getting it to work on Mac OS X.

First of all, I highly recommend the MacVim port of Vim (not to be confused with You can get the latest version (7.3.53 at time of post) at github:

The Vim-R-plugin that Michal mentioned works on OS X with the Screen plugin as well. However, a simpler method is to use one of the following two OS X specific scripts that rely on AppleScript.

R.vim uses AppleScript to send selected lines of code to an R buffer. Simply hit <F3> to run the selected lines in R.  If R is not open, it will automatically open a new session. Note that it opens instead of so if you need to run the 64-bit version you’ll have to tinker with the script a bit.

R-MacOSX is also pretty straight forward, although I couldn’t get it working properly. It defaults to <Cmd-E> to run selected lines and <Shift-Cmd-E> to source the entire file.

In either case, key mappings are customizable but personally, I have no trouble with <F3> to execute code using R.vim.  Neither are as full-featured as Vim-R-plugin but I find them sufficient as all I really need is to send blocks of code to R.

Happy Vimming!

Installing rgdal on Mac OS X


The rgdal package contains bindings from R to the GDAL (Geospatial Data Abstraction Library) as well as the PROJ library. It is a dependency for numerous spatial statistics packages. Note that the binaries on the rgdal homepage are outdated — the most up-to-date version of the rgdal package can be found on CRAN.

Unsurprisingly, rgdal requires both the GDAL and PROJ framework to run. Both frameworks for Mac OS X are kindly maintained by William Kyngesburye and can be found here:

Unix Compatibility Frameworks

I recommend installing GDAL Complete as it contains both required frameworks in a neat little package.
At the time of writing, there are two versions of GDAL Complete:

  • GDAL 1.7 Complete
  • GDAL 1.6 Complete

Both should work for rgdal but note that currently, the stable Mac OS X version of Quantum GIS (QGIS 1.4) only runs with GDAL 1.6, so if you need to use QGIS as well, I would recommend installing GDAL 1.6.  If you’ve installed GDAL 1.7, then you’ll have to use the developer’s release of QGIS.
(May 19, 2011 update: Install GDAL 1.8 Complete as it works for both standard and developer’s release of QGIS)

Next, assuming you installed GDAL above with the default paths, you’ll need to install the R package from source (get package source here) with modified arguments either with install.packages() or through the terminal:

R CMD INSTALL --configure-args='--with-gdal-config=/Library/Frameworks/GDAL.framework/unix/bin/gdal-config --with-proj-include=/Library/Frameworks/PROJ.framework/unix/include --with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib' rgdal_0.6-33.tar.gz

If you’re getting this error:

Error: package ‘rgdal’ is not installed for ‘arch=i386′

when trying to load the rgdal package, it is because your version of rgdal was not compiled for the 32-bit version of R. You’ll need to run the 64-bit version of R ( on Macs).

You may also need to update the base version of the sp package as well as any other dependencies.

Hello world!

No Comments »

Throughout the course of my research, I come across a lot of obstacles and nuisances that are either undocumented or documented poorly.  Therefore, I decided to throw up this blog as a repository of sorts to store all of these little tidbits of information with the hope that it will save somebody somewhere a few minutes of frustration.  But even if it doesn’t, I’m sure it’ll help me in the future, if only to serve as a reference.

My research deals mainly with statistical computing and involves a lot of R programming so most of the posts will revolve around that.  I’m also an Apple user and although R on Macs has come a long way, there is still room for improvement.  Hopefully this blog will be a small step towards making Mac OS X a statistics research-friendly platform.