3

After upgrading to MacOS Mojave (10.14.1), I'm no longer able to install rJava for R version 3.5.1 with Java version "1.8.0_102" installed.

I tried the previous solution for MacOS 10.11 but it still did not work, giving this error:

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-9.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
JohnSG
  • 1,567
  • 14
  • 26

4 Answers4

6

Posting the solution I found in case it helps others -- I don't quite understand why this work or if it's the right way so looking for better alternatives!

This issue lead to this Apple forum where it's stated

For legacy software that looks for the macOS headers in the base system under /usr/include, please install the package file located at: /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14. pkg

To do this, open terminal and run these commands

cd /Library/Developer/CommandLineTools/Packages/
open macOS_SDK_headers_for_macOS_10.14.pkg

then follow prompts to install the package.

After this, in the terminal, configure rJava and install as in the previous answer

sudo R CMD javareconf

R -e "install.packages('rJava')"

and it should install without problem.

M--
  • 25,431
  • 8
  • 61
  • 93
JohnSG
  • 1,567
  • 14
  • 26
  • You may need to install the CommandLineTools directory as well. That can be performed with 'sudo xcode-select --install'. – Peter N. Steinmetz Dec 07 '18 at 18:48
  • Thanks @PeterN.Steinmetz -- I did try that (following some other link) without success...though I think it was necessary for the above to work. – JohnSG Dec 11 '18 at 02:55
2

After installing JDK 11.04 LTS I rain into the same error in R Studio on Mojave

R was expecting Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk

Despite running sudo R CMD javareconf the error still persisted

Therefore I browsed to /Library/Java/JavaVirtualMachines/ in finder and renamed the folder "jdk-11.0.4.jdk" to "jdk-11.0.1.jdk"

Restarted R and both library(rJava) and library(xlsx) now work.

Hope this helps someone

tomlincr
  • 71
  • 1
  • 4
1

I ran into the exact problem. I solved it by:

  1. Install the latest version of Java (dmg file)

  2. Install rJava in Studio: install.packages("rJava")

  3. In the terminal: sudo mv jdk-12.0.1.jdk jdk-11.0.1.jdk

Otherwise the following error will appear in Rstudio:

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
  1. In Rstudio: library(rJava)

  2. rJava should have been loaded without issues.

Stephan Hogenboom
  • 1,543
  • 2
  • 17
  • 29
Ruser
  • 11
  • 1
  • Glad to know that this works. I'd be a little concerned about overwriting the version of Java...presumably there are actual differences. At the least, I wonder if you could make a symlink instead of actually renaming the entire directory? – JohnSG Jun 06 '19 at 13:03
1

I ran into same issue, when i was trying to install "rJava" in my macOs (Mojave version).

Below steps i executed to resolve issue.

R version : 3.6.1

issue : configure: error: one or more Java tools are missing. *** JDK is incomplete! Please make sure you have a complete JDK. JRE is not sufficient.

solution : execute below command in your terminal

  1. $ /usr/libexec/java_home -V
    Matching Java Virtual Machines (1):
        1.8.0_162, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk(your Java version)/Contents/Home
  1. $ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home

  2. $ export PATH=$JAVA_HOME/bin:$PATH

  3. $ R CMD javareconf

  4. $ R --quiet -e 'install.packages("rJava", type="source", repos="http://cran.us.r-project.org")'

Bill Chen
  • 1,699
  • 14
  • 24
Tapan Hegde
  • 1,222
  • 1
  • 8
  • 25