Unable to load rJava in RStudio

2019-03-03 01:02发布

问题:

I have been trying to load rJava onto my RStudio setup and it just won't work. It installs fine but doesn't load when I use the command library(rJava).

Here's what I've tried:-

  1. I have installed the latest version of jdk which is jdk 9.0.1.
  2. I have tried changing the JAVA_HOME environment variable to the jdk location.
  3. I have tried everything in this question as well but it didn't work.

I have attached the screenshot of the error message:

I am working on a MacBook.

回答1:

There is a very specific sequence of steps that must be taken to get rJava to work on a Macbook, as documented in rJava Issues #86.

  1. Download and install Java from Oracle
  2. Uninstall any previously installed version of rJava
  3. Add JAVA_HOME to your .bashrc
  4. Close & restart terminal, R and RStudio sessions so they pick up the updated JAVA_HOME
  5. Use install.packages() to install rJava

See the URL link above for additional details on each step.