Installing rgl in R under OS X Lion

I had recently updated my copy of R to 2.15.1 and ended up needing to reinstall some libraries, including rgl.

If you use this R library, it can be tricky to install with the built-in build of Mesa/OpenGL in Lion. In fact, a straightforward install.packages("rgl") just won’t work at all.

But after using MacPorts to install freeglut, I found the following R command helps build rgl successfully:

install.packages(“rgl”, repos=”http://R-Forge.R-project.org”, configure.args=”–disable-cocoa –with-gl-includes=/opt/local/include –with-gl-libs=/opt/local/lib –with-x”)

Once installed, rgl can make cool figures, like this: