0

when I execute the following code on Mac, I got this

**> library(xlsx)**

Loading required package: 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
Error: package ‘rJava’ could not be loaded

I saw some posts here that changes the directory of Java Home, but they are all in Windows system. I am wondering how can I fix this in a Mac environment?

  • At the risk of asking a stupid question, you did install `rJava` first, right? Anyway, if you want to update the JAVA_HOME path on a Mac it should be straightforward: http://www.sajeconsultants.com/how-to-set-java_home-on-mac-os-x/ – Hack-R Sep 03 '17 at 21:57
  • Marking it as duplicate using old answer is not quite helping here. The issue here is, that macOS solution is quite different here. And, it depends on R version as well. Take a look here: http://www.owsiak.org/?p=3718 and here: http://www.owsiak.org/?p=3671 for a detailed solution. – Oo.oO Sep 05 '17 at 19:06

1 Answers1

0

Try this

  1. If homebrew is not installed, install it from https://brew.sh/
  2. Run this from terminal: brew cask install java
  3. Reinstall rJava from R console

In general, and to avoid similar problems in the future, I suggest to follow my post to install R using homebrew http://pacha.hk/2017-07-12_r_and_python_via_homebrew.html

Doing that solves path problems and related stuff that can re-appear if later you want to use R database tools and related.

pachadotdev
  • 3,345
  • 6
  • 33
  • 60