3
votes

Although I'm running the risk of duplicating questions, I have yet to find a solution to my configuration.

I'm trying to load rJava into RStudio.

I am using the latest Mac OS x, with a build of Rstudio that's only a couple of months old, and I've just installed JDK x64 12.0.1 The version of rJava is 0.9-11

On executing:

library(rJava)

I am confronted with the usual:

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.5/Resources/library/rJava/libs/rJava.so': dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so Reason: image not found

I've tried setting my Java home path to:

Sys.setenv(JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home')

But that doesn't make any difference.

I've clearly missed the rJava instructions somewhere which lays out how to install the package on all computer setups. I'd appreciate some assistance.

EDIT #1

Following the link provided in the comments below, I managed to get the latest version of Java JDK running through rJava in RStudio. The document "R, Java, rJava and macOS adventures" isn't complete and doesn't work off the cuff. You'll probably end up hacking about to get it working.

I needed rJava to run venneuler, unfortunately, this was not work using the latest Oracle JDK version 12:

WARNING: Initial Java 12 release has broken JNI support and does NOT work. Use stable Java 11 (or watch for 12u if available). ERROR: Java exception occurred during rJava bootstrap - see stderr for Java stack trace.

I'm going to try (wish me luck) to get two versions of Java on my machine and have RStudio recognise the right one.

Edit 2

Pure luck I think I have Java 11 working: enter image description here

2
Did you do install.packages(rJava) first?Jaap
you also need to make sure you have java installed in your Mac and correctly configuredFMM
Please also look at the linked questions in the right sidebar under the heading Related.Jaap
@Jaap Yes - that's installed. And Java is installed.Anthony Nash

2 Answers

5
votes

I had the this issue as well on my mac (OSX High Sierra v10.13.6) and could not solve it by following previous suggestions (reinstall JDK, R CMD javareconf or setting JAVA_HOME). The same error message persisted:

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.5/Resources/library/rJava/libs/rJava.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so
  Reason: image not found

After looking closely at the error message, I found that I had JDK12, but R kept looking for libjvm.dylib under the JDK11 folder which does not exist in my system. The path to JDK11 appeared in Sys.get('DYLD_FALLBACK_LIBRARY_PATH'), but overwriting this variable did not help. Neither did dyn.load('PATH_TO_YOUR_JDK').

And then the second to last line of the error message caught my eye: the path to libjvm.dylib was referenced from rJava.so. Why not take a look at this file? At the end, I opened the rJava.so, found the JDK11 path and replaced it with JDK12 path, and rJava loaded perfectly. Hope this helps other people with the same issue.

R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tabulizer_0.2.2 rJava_0.9-11   

loaded via a namespace (and not attached):
 [1] tabulizerjars_1.0.1 compiler_3.5.2      assertthat_0.2.1    cli_1.1.0           tools_3.5.2         withr_2.1.2        
 [7] rstudioapi_0.10     yaml_2.2.0          crayon_1.3.4        png_0.1-7           sessioninfo_1.1.1  
0
votes

I had the same issue and I was able to fix it by searching, but I don't remember exactly the step that I've done but I looked again and I found this answer and I hope it'll work for you. You'll have to run this command in a terminal. I don't know if I can post link but I just typed "rjava lib Rstudio error" and I find a couple of different solutions so you might give them a look if this doesn't work.

sudo R CMD javareconf