Loading the “rJava” package into RStudio


Poking around the interwebs, everyone seems to get into trouble loading the rJava package into RStudio. It seems like there are enough people trying to make this work that it should just work out of the box, but then again, what do I know?

Here’s what worked for me:

jdk <- system2("/usr/libexec/java_home", stdout=TRUE)
dyn.load(paste(jdk, "jre/lib/server/libjvm.dylib", sep="/"))
library("rJava")

This manually figures out where libjvm.dylib is and loads it prior to opening the rJava library. Ick.