Loading rJava into R (3.4.1) with OS Sierra

I had a problem with rJava in the latest version of R (3.4.1), Mac (10.12.5) and Java VM (1.8.0_131, x86_64 :)

Problem:

I try to follow this guide

scottdhoover.wordpress.com/2013/03/05/a-basic-rjava-example/

To run rJava in R.

Some code from r:

Library (rJava) .jinit (") .jclassPath () [1]" /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/java "

s <-.jnew ("java / lang / String", "Hello World!") .jcall (s, "I", "length") [1] 12

This actually works .. but when I try with my files:

.jaddClassPath ("/ Users / Camilo / Desktop / 20170711_Java2R") .jclassPath () [1] "/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/java" "/ Users / Camilo / Desktop / 20170711_Java2R "

myExchange <-.jnew ("myExchange") Error in .jnew ("myExchange"): java.lang.ClassNotFoundException

where the myExchange.java file is the same as in the manual and is located in the folder on the desktop.

What I've done:

Basically, I tried installing rJava from R and did not work. Then I follow two guides to be able to load the rJava package into R from the source

I follow this guide:

https://github.com/snowflakedb/dplyr-snowflakedb/wiki/Configuring-R-rJava-RJDBC-on-Mac-OS-X (for downloading rJava)

Where are both

R CMD javareconf /usr/libexec/java_home -V 

It looks exactly as it should be.

To get rid of the OpenMP problem that people usually use, follow this guide:

http://thecoatlessprofessor.com/programming/openmp-in-r-on-os-x/#clang-before-3-4-0 (To get rid of the OpenMP problem that all people have).

Finally, I create a symbolic link using this code

  sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib 

and I managed to install the library from R.

But! When I try it from the terminal, I get this error

  ld: library not found for -lomp clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [libjri.jnilib] Error 1 make[1]: *** [src/JRI.jar] Error 2 make: *** [jri] Error 2 ERROR: compilation failed for package 'rJava' 

So me too: the library or the symbolic link should also be missing .. but there is no such file as in llvm (were solved in llvm with ld: library not found for -lomp )

I know that the error "ClassNotFoundExceptions" may be related to PATH, but it should be fine, because it was declared at the beginning.

btw, I also check the .R / Makevars file, which looks like

  CC=/usr/local/clang4/bin/clang CXX=/usr/local/clang4/bin/clang++ LDFLAGS=-L/usr/local/clang4/lib 

Any ideas how to solve them? Thank you in advance! Hope this is clear.

+5
source share
2 answers

For me there was a solution to install https://github.com/coatless/r-macos-clang and add a link

 sudo ln -s /usr/local/clang4/lib/libomp.dylib /usr/local/lib/libomp.dylib 

Prior to R CMD javareconf I unset JAVA_HOME .

+2
source

This is a confusing issue and depends on your version of R.

For R 3.4 users on a Mac Sierra, ignore all the noise about gcc, clang, llvm. R 3.4 uses clang4. Period. Therefore you must do

  • Install clang4
  • Change .R / Makevars to point to clang4
  • Install Java 8
  • R CMD javareconf
  • To fix the communication problem, sudo ln -s /usr/local/clang4/lib/libomp.dylib /usr/local/lib/libomp.dylib

Then you can successfully install rJava.

In addition, rJava will not load properly in an earlier RStudio. So make sure you upgrade to the latest version of RStudio.

+1
source

Source: https://habr.com/ru/post/1269746/


All Articles