1

I am using macOS Sierra and R version 3.4.0. I installed the package "rJava" using RStudio:

install.packages("rJava")
Warning in install.packages :
  cannot open URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.4/PACKAGES.rds': HTTP status was '404 Not Found'
trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.4/rJava_0.9-8.tgz'
Content type 'application/x-gzip' length 627959 bytes (613 KB)
==================================================
downloaded 613 KB


The downloaded binary packages are in
    /var/folders/tq/f5jbfqp97y52w_y7byn05_fw0000gn/T//RtmpTdEVbA/downloaded_packages

Then when I try to run rJava I get:

> require(rJava)
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
sbac
  • 1,897
  • 1
  • 18
  • 31
  • 1
    No I want to use rJava to run RNetLogo. – sbac Jul 27 '17 at 13:17
  • See if executing `R CMD javareconf` in a Terminal solves the problem. – Bhas Jul 27 '17 at 13:39
  • Yes, I tried it before and now once again, without any luck. – sbac Jul 27 '17 at 13:45
  • have you tried installing from source? `install.packages("rJava",type="source")` Also, see [this related SO](https://stackoverflow.com/questions/30738974/rjava-load-error-in-rstudio-r-after-upgrading-to-osx-yosemite) – hongsy Jul 28 '17 at 06:29
  • 3
    The related SO solved my problem. I just did `sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib` – sbac Jul 28 '17 at 09:37
  • If you're using RStudio, make sure you have [v1.0.153 or greater](https://www.rstudio.com/products/rstudio/download/) as it contains some fixes for the loading of `rJava` + R 3.4.0 in particular. – Kevin Ushey Jul 29 '17 at 02:46
  • awesome :) glad i helped :) – hongsy Aug 01 '17 at 06:12

1 Answers1

2

R, rJava and Java are little bit messy in macOS. In general, you have to make sure to properly configure all the elements. There is a clash between Oracle's and Apple's version.

Take a look here for very detailed instructions: R, Java, rJava and macOS adventures

I don't post the content here - it's quite long.

Oo.oO
  • 12,464
  • 3
  • 23
  • 45