Run R and JGR in macOS Sierra

When you try to install R and Rstudio in macOS Sierra and run JGR, there might be an error that the package can not find JVM when trying to load rJava.

Here is a solution:

  • Download Java SDK

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

In Mac Terminal:  

  • Type in commend (not including lines start with #):

sudo R CMD javareconf

#####You should see the configuration info

sudo ln -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib

#####It will ask you yes or no, type “y” then return

Reference: http://conjugateprior.org/2014/12/r-java8-osx/

In RStudio Console:

  • Type in commend:

dyn.load(paste0(system2(‘/usr/libexec/java_home’, stdout = TRUE), ‘/jre/lib/server/libjvm.dylib’))

library(rJava)

#####There should not have error

library(JGR)

#####You should be able to see some warnings.

JGR()

#####JGR should be loaded

Reference: http://paulklemm.com/blog/2017-02-12-fix-onload-failed-rjava-macos/

To run later

In RStudio Console:

  • Type in commend:

dyn.load(paste0(system2(‘/usr/libexec/java_home’, stdout = TRUE), ‘/jre/lib/server/libjvm.dylib’))

library(JGR)

JGR()

Leave a Reply

Your email address will not be published. Required fields are marked *