Getting rJava/JRI to work (It is painful!)

First you can download the the tar file from http://www.rforge.net/rJava/files/. I used the rJava_0.8-5.tar.gz. Then I unzip the file to my desktop. You can find two sample files under ~/Desktop/rJava/jri/examples. Currently, I just need jri.

When you run the test file in Eclipse, you might get error:

  • Cannot find JRI native library

You need to copy the “libjri.so” to “java.library.path”. Use following to show the path:

  • System.out.println(System.getProperty(“java.library.path”));

Use this command:

  • sudo cp ~/Desktop/rJava/jri/libjri.so  /usr/lib

Another error coming: “cannot find system Renviron”.

For this error, you have several solutions:

  • set up “environment” in Eclipse per file under “Run Configuration…” (works, not productive)
  • set up system environment variables (works for whole Eclipse)
  • create a script to pass the information (not pass my test yet)

Reference:

  1. https://help.ubuntu.com/community/EnvironmentVariables
  2. http://sonivis.org/wiki/index.php/Installation_GNU_R
  3. Script: http://sonivis.org/startupEclipse
  4. http://sonivis.org/wiki/index.php/Troubleshooting#cannot_find_system_Renviron
  5. http://blog.pingoured.fr/index.php?post/2009/03/23/Getting-rJava/JRI-to-work%3A
Advertisements

9 thoughts on “Getting rJava/JRI to work (It is painful!)

  1. Try: “export R_HOME=/usr/lib64/R/” via command line terminal. Please replace the directory to where you install the R. Then start eclipse from the same terminal.

  2. hi autofei

    I installed the library rJava using the command R – install.packages (rJava), and i configured my $ R_HOME = / Library / Frameworks / R.framework / Resources.

    In my snow leopard, don’t exists a path call lib64. All resorces are in R.Framework

    thanks

  3. Hi, Helas: Sorry, I do not have Mac. Of course, you do not have “/usr/lib64/R/”, which is under Linux. Just use whatever directory for your installation and OS.

  4. Hello Sir,
    I ran into trouble with R again and while searching found your blog! Anyway I made this quick (simplistic) check for when my R code goes bad it runs this simple output to tell users/devs how to debug this common problem.

    System.out.println(“==================================================================================================”);
    System.out.println(” Quick check of variables”);
    System.out.println(“==================================================================================================”);
    System.out.println(“CHECK(1 of 2)”);
    System.out.println(“if you get [Cannot find JRI native library] this is wrong”);
    System.out.println(” java.library.path=”+System.getProperty(“java.library.path”));
    System.out.println(” Above should include the path to jri, example:R/x86_64-pc-linux-gnu-library/2.10/rJava/jri”);
    System.out.println(” This should be passed to the jvm via -D”);
    System.out.println(” full example given in bash:”);
    System.out.println(” $java -Xms1024m -Xmx6144m -D~/R/x86_64-pc-linux-gnu-library/2.10/rJava/jri -jar MyProgram.jar >test.csv 2>err.log”);
    System.out.println(“CHECK(2 of 2)”);
    System.out.println(“If you get [cannot find system Renviron] this is wrong”);
    System.out.println(” R_HOME=”+System.getProperty(“R_HOME”));
    System.out.println(” Above should include the path to R, example:/usr/lib/R”);
    System.out.println(” full example given in bash:”);
    System.out.println(” $export R_HOME=/usr/lib/R:$R_HOME”);

    Hope this clarifies my problems as well as everyone else’s problems in the future. Hope all is well

  5. greetings to everybody, I want to share with you something very useful, at least to me, in this page explains exactly what kind of thing have to do for configure correctly the JRI in Netbeans and Eclipse,. This configuration is in Ubuntu, but works

    http://blog.binfalse.de/2011/02/talking-r-through-java/comment-page-1/#comment-149

    the only thing that have to do aditionaly is put in the Terminal the follow instruction> sudo R CMD javareconf, for especify in R where is the jvm. Sorry for my english, but I hope this information maybe be useful for all, regards.

  6. Hi guys.

    I get the message “cannot find system Renviron”. I have already set the R_HOME environment variable to the path indicated by my “which R” command, which is “/usr/bin/R”. Checking in java, I get the right value:

    System.out.println(System.getenv(“R_HOME”)); //Returns /usr/bin/R
    System.out.println(System.getProperty(“R_HOME”)); //Returns null

    What am I missing?

    I am using Eclipse, on Ubultu 12.04.

    Any help?

    1. Just found the solution. I added the wrong path to my environment variable. I should add the /usr/lib/R in the variable.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s