Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java R Interface (JRI) Setup

I am trying to setup the Java/R interface (bundled in the R "rJava" package), but I am having some trouble (despite trying many suggestions here and on other forums).

I am running Windows 7, jdk1.7.0_05, Eclipse, R 2.15.2. These are all 64 bit installations.

The steps I have followed to attempt to get the example running are as follows:

  1. Install rJava within the R GUI: install.packages('rJava') - installs to C:\Users\USERNAME\Documents\R\win-library\2.15\rJava\
  2. Setup environment variables: R_HOME = "C:\Program Files\R\R-2.15.2", additions to PATH = "C:\Program Files\Java\jdk1.7.0_05\bin";"C:\Program Files\Java\jdk1.7.0_05\jre\bin\server";"C:\Program Files\R\R-2.15.2\bin\x64";"C:\Users\USERNAME\Documents\R\win-library\2.15\rJava\jri\x64"
  3. Setup example project in Eclipse, setting VM argument: -Djava.library.path="C:\Users\USERNAME\Documents\R\win-library\2.15\rJava\jri\x64"
  4. Restart R and load rJava with command: libraries('rJava')
  5. Run the example program, obtaining the following exception:

Cannot find JRI native library! Please make sure that the JRI native library is in a directory listed in java.library.path.

java.lang.UnsatisfiedLinkError: C:\Users\USERNAME\Documents\R\win-library\2.15\rJava\jri\x64\jri.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary1(Unknown Source)
    at java.lang.ClassLoader.loadLibrary0(Unknown Source)
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at org.rosuda.JRI.Rengine.<clinit>(Rengine.java:19)
    at test.JRITest.main(JRITest.java:64)

I have verified "java.library.path" is set as expected since: System.out.println("JLP = " + System.getProperty("java.library.path")); outputs the correct path.

I think rJava may not have installed fully (have tried reinstalling), but I'm not sure how to check this. The only JAR in "...\rJava\jri" or any of its subdirectories is "JRI.jar" and the examples directory seems incomplete.

Does anyone have suggestions on what may be going wrong here?

It seems the JRI website (http://www.rforge.net/JRI/index.html) has been down today, not sure if anyone knows another source to download from (other than direct from CRAN).

Thanks.

like image 357
user1415528 Avatar asked Sep 30 '13 18:09

user1415528


2 Answers

Try to copy all dll files(*.dll) which in R directory to JAVA_PATH/bin. After that load the the jri native lib like:

//Right under your R class
   static {
    System.loadLibrary("jri");      
   }

I had the same problem and solved it by this method.

Thx

like image 196
Oguz Avatar answered Sep 25 '22 06:09

Oguz


After reading a lot of posts and trying a lot of different solutions, it is finally working. I'm using Windows 7 64bits and I'll list the steps that I did to make it work properly.

  1. Install package rJava using R install.packages("rJava")
  2. Right-click on My Computer > Properties > Advanced System Settings > Environment Variables...
  3. Find Var PATH or CLASSPATH and Edit, add the following paths: C:\Program Files\R\R-3.4.0\bin\x64;C:\Users\ [User Name]\Documents\R\win-library\3.4\rJava\jri\x64
  4. Go to C:\Program Files\R\R-3.4.0\bin\x64 and copy all .dll files (here they are: R.dll,Rblas.dll,Rgraphapp.dll,Riconv.dll,Rlapack.dll)
  5. Past them at C:\Program Files\Java\jdk1.8.0_144\bin
  6. When you create your java project, remeber to add the JRI.jar, JRIEngine.jar and Rengine.jar to your project build path. They are located at C:\Users\ [User name]\Documents\R\win-library\3.4\rJava\jri
  7. After doing all this, I was still getting an error, that was solved when I went to C:\Users\ [User Name]\Documents\R\win-library\3.4\rJava\jri\x64 and copy the jri.dll and past inside my Java Project, like the following image:

enter image description here

Here is a code example and its output:

enter image description here

This example was retrieved from: http://codophile.com/2015/04/15/how-to-integrate-r-with-java-using-rjava/

like image 23
Everton Reis Avatar answered Sep 25 '22 06:09

Everton Reis