1

Here's the error I get:

> library(rJava)
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 '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: @rpath/libjvm.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so
  Reason: image not found

I see this is by no means a unique problem.. I've tried the solutions here, here and here. No success.

Some more details: I'm using R GUI, but I also can't load rJava through R terminal. I also didn't have any issue with rJava on R 3.3.s

Lucas De Abreu Maia
  • 598
  • 2
  • 6
  • 19

2 Answers2

1

You have two options here:

  1. get older release of R and use precompiled version of rJava

  2. get rJava sources and compile it for yourself

Note that rJava (most recent sources) require some features that are not embedded inside XCode and clang that is available via AppStore. You will need to do some low level stuff when it comes to building rJava package.

You can find detailed instruction here: http://www.owsiak.org/r-3-4-rjava-macos-and-even-more-mess/

If you decide to use older release of R, it's still a struggle to get it working, but way less to do: http://www.owsiak.org/r-java-rjava-and-macos-adventures/

Oo.oO
  • 12,464
  • 3
  • 23
  • 45
  • I downgraded to R 3.3 and got it working fine. But I'd rather not have to use an older version of R. Will try your second solution. – Lucas De Abreu Maia Nov 05 '17 at 02:43
  • The issue here is that binary version of package - for macOS - was not yet released. So, you need to build it by yourself. However, there are other constraints that make process little bit more complex :( – Oo.oO Nov 05 '17 at 09:00
1

JAVA_HOME path is different for different version of MAC OS. In some cases there is /jre folder and in some cases it is not after /Home director manually go towards /server folder with CD command in terminal and using pwd copy the entire path use that to set the java.home then you can easily load rJava library. This is how I was able to fix the issue

options("java.home"="/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/lib")

Sys.setenv(LD_LIBRARY_PATH='$JAVA_HOME/server')

dyn.load('/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/lib/server/libjvm.dylib')

library(rJava)
vinay karagod
  • 256
  • 1
  • 3
  • 18