0

Bear in mind that I am computer illiterate and new to R. I have installed the rJava package in R studio version 1.0.143 and installed Java 8 (using MacOS Sierra). When I try to load the rJava package:

library(rJava)

I get the following error

Unable to find any JVMs matching version "(null)".
No Java runtime present, try --request to install.
Error: package or namespace load failed for ‘rJava’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object 
 '/Users/cormac/Library/R/3.4/library/rJava/libs/rJava.so':
 dlopen(/Users/cormac/Library/R/3.4/library/rJava/libs/rJava.so, 6): 
 Library not loaded: @rpath/libjvm.dylib
 Referenced from: 
/Users/cormac/Library/R/3.4/library/rJava/libs/rJava.so
Reason: image not found
In addition: Warning messages:
1: package ‘rJava’ was built under R version 3.4.2 
2: running command '/usr/libexec/java_home' had status 1 

Could somebody help me to interpret this error message? There is probably a very simple solution, but I am completely lost. Thank you!!

Len Greski
  • 10,505
  • 2
  • 22
  • 33
  • Can you shut down R completely and do `R CMD javareconf JAVA_CPPFLAGS=-I/System/Library/Frameworks/JavaVM.framework/Headers` and see what happens? – hrbrmstr Nov 02 '17 at 20:43
  • Hi, I figured out the problem (very obvious solution). But thank you for your help! – Cormac Martinez del Rio Nov 03 '17 at 16:01
  • If you post it as an answer, it may help others and folks can up-vote you and you can (IIRC) accept it in a few weeks. – hrbrmstr Nov 03 '17 at 18:14
  • What was the solution here? – user2300940 Jan 11 '18 at 13:57
  • Hello all, I tried a variety of actions based on six or so stackoverflow discussions, and nothing worked. My solution was to do everything the same way, but while running Windows through bootcamp on my mac. I'm sorry for not having any more constructive advice for anybody else who runs into this problem! I appreciate your help. – Cormac Martinez del Rio Jan 12 '18 at 21:21

1 Answers1

0

As noted in Unable to load rJava in RStudio, 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.

Len Greski
  • 10,505
  • 2
  • 22
  • 33