RJava loads on Terminal but fails to load on Rstudio

I am trying to load the RJava on RStudio and I am getting this error message.

> 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.6/Resources/library/rJava/libs/rJava.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.6/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.6/Resources/library/rJava/libs/rJava.so
  Reason: image not found

However, it works when I load on Terminal.

If someone can help me to solve this I would appreciate.

I am using a macOS Catalina Version 10.15.2
R version 3.6.1
Platform: x86_64-apple-darwin15.6.0 (64-bit)
RStudio Version 1.2.5001

It looks like there is a missing link between Java and RStudio. It's been a while since I installed rJava on my machine and the following is from my notes for installing tabulizer packge (late 2017/early 2018).

Assuming Java and Java Development Kit is installed (they aren't installed together), run the following line in the R console. If there are any errors, check to see if the paths exist.

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

If it is successful, then install rJava. See the original tabulizer thread for more information on installing rJava and linking it with RStudio. I think this should work. Let me know if it doesn't and I will investigate my old scripts to see if I updated this code.

Hi dcruvolo,

Thank you for your answer. I tried what you suggested and I am getting an error. Apparently the first path exists but "'/jre/lib/server/libjvm.dylib'" doesn't.

I checked the Java and JDK version installed and I have

13.0.1, x86_64: "Java SE 13.0.1" /Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home*
/Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home*

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

Sorry, to hear you are having difficulties. Things have definitely changed since the last time I set up rJava. I found this rJava issue and I was able to get rJava working on my machine (although I'm on Mojave 10.14.6). Does running the following command work?

R CMD javareconf