rJava, Yosemite, R, RStudio

kludgetastic, DH

A new OS upgrade means new Java problems. I use MALLET, which depends on rJava, which depends on Java. Here’s what I did to get things working (apparently, for now).

  1. Install the latest Java JDK from Oracle. 1.8.0_25 here; I see I’m lagging a few versions behind. As usual. Stupid Java.

  2. install.packages("rJava"). You may have to install from source (happened by default for me), but then again maybe not. Anyway, if you successfully install the package, rJava will now load, but .jinit() will fail. [Edited, 5/26/15.]

  3. Download and install Java for OS X 2014-001 from Apple. Yes, this installs Java 1.6. You need this hanging around for Java 1.8 to work. Seriously: see the comments by the rJava developer, Simon Urbanek, here.

  4. library(rJava) and .jinit() now work in R in the shell.

  5. RStudio, however, does not find the right magical java files. One needs to set an environment variable, DYLD_FALLBACK_LIBRARY_PATH, for the application. The easiest way is to launch RStudio from the shell with an alias like this: alias rstudio="DYLD_FALLBACK_LIBRARY_PATH=/Library/Java/JavaVirtualMachines/jdk$(java -version 2>&1 | head -n 1 | cut -d'"' -f 2).jdk/Contents/Home/jre/lib/server/: open -a RStudio"

    The correct DYLD_FALLBACK_LIBRARY_PATH value depends on your current java version, so the $() bit figures that out.

    If you want RStudio to launch with the present working directory as R’s working directory, use rstudio ..

  6. The R mallet package can now be installed and run. On my system (OS X 10.10.2). So far. Thanks for nothing, Java.

  7. To get rJava to re-install after upgrading R, a further step was necessary for me: running R CMD javareconf with appropriate options. I install and upgrade R from homebrew/science, which recommends: R CMD javareconf JAVA_CPPFLAGS=-I/System/Library/Frameworks/JavaVM.framework/Headers. No sudo, and no additional flags pointing to the current JDK version. This worked…for me. [Edited, 7/3/15.]