Install the latest Java JDK from Oracle.
1.8.0_25here; I see I’m lagging a few versions behind. As usual. Stupid Java.
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,
rJavawill now load, but
.jinit()will fail. [Edited, 5/26/15.]
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.
.jinit()now work in R in the shell.
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"
DYLD_FALLBACK_LIBRARY_PATHvalue 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
malletpackage can now be installed and run. On my system (OS X 10.10.2). So far. Thanks for nothing, Java.
To get rJava to re-install after upgrading R, a further step was necessary for me: running
R CMD javareconfwith 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.]