3

I'm new to R and was attempting to call a simple rJava test program from java. I have done the necessary path settings and when I am attempting to create a Rengine instance the code is failing. The issue seems to be with C [R.dll+0x26036]. However, I am new to this and not being able to figure out the issue. Any help will be welcome.

My code :

import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
public class First_R {
public static void main (String args []) {

    System.out.println("Start");
    Rengine.DEBUG = 5;

    System.out.println("Starting Rengine..");
    System.out.println("R_HOME =" + System.getenv("R_HOME"));
    final Rengine re = new Rengine ();
    // Check if the session is working.
    if (!re.waitForR()) {
        return;
    }
    re.assign("x", new double[] {1.5, 2.5, 3.5});
    REXP result = re.eval("(sum(x))");
    System.out.println(result.asDouble());
    re.end();
}

}

The output:

Start Starting Rengine.. R_HOME =D:\Program Files\R\R-3.2.0\bin\

A fatal error has been detected by the Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006c726036, pid=4588, tid=1872

JRE version: Java(TM) SE Runtime Environment (8.0_45-b14) (build 1.8.0_45-b14) Java VM: Java HotSpot(TM) 64-Bit Server VM (25.45-b02 mixed mode windows-amd64 compressed oops) Problematic frame: C [R.dll+0x26036]

Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

An error report file with more information is saved as:

Yehoshaphat Schellekens
  • 2,305
  • 2
  • 22
  • 49
Ayon
  • 315
  • 3
  • 20
  • Have you set the VM options? you need to set up your VM options, for example in netbeans ive inserted the following option for JRI -Djava.library.path='C:\Program Files\R\R-2.15.3\library\rJava\jri\x64' – Yehoshaphat Schellekens Jun 01 '15 at 10:53
  • You're question ended abruptly: "An error report file with more information is saved as:" ...? – Christopher Bottoms Jun 01 '15 at 12:10
  • @YehoshaphatSchellekens, I added `System.setProperty("JRI", "-Djava.library.path='D:/Misc/RLib/rJava/jri/x64'");` to my code. It still returns the same error. Also as I have installed rJava to my exclipse I have set the path for the dlls and JRI in my preferences. – Ayon Jun 02 '15 at 05:46

2 Answers2

2

In Your environment setup, please change R_HOME to D:\Program Files\R\R-3.2.0 and not R_HOME =D:\Program Files\R\R-3.2.0\bin\, please let me know if that does the job :), notice that the your code works for me (using nicola's advice as well)

package rundavid;

import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;



public class RunDavid {


public static void main (String args []) {



    System.out.println("R_HOME =" + System.getenv("R_HOME"));


    Rengine re = new Rengine (new String [] {"--vanilla"}, false, null);
    // Check if the session is working.
    if (!re.waitForR()) {
        return;
    }
    re.assign("x", new double[] {1.5, 2.5, 3.5});
    REXP result = re.eval("(sum(x))");
    System.out.println(result.asDouble());
    re.end();
}}

the output:

run:
R_HOME =C:\Program Files\R\R-2.15.3
7.5
BUILD SUCCESSFUL (total time: 0 seconds)

Also you need to set up D:\Program Files\R\R-3.2.0\bin\x64;D:\Misc\RLib\rJava\jri\x64 This you need to set up in vm options, and not as environment variable. this is how its done in Netbeans (that what im using):

  1. Right click on the project, then click on properties
  2. Then choose the run
  3. Insert the VM options as following: How to set VM options in Net beans
Yehoshaphat Schellekens
  • 2,305
  • 2
  • 22
  • 49
  • it still does not work for me . Am i doing something wrong with the settings? I am posting the full output here : – Ayon Jun 04 '15 at 05:11
  • Can you please post all your environment variables? – Yehoshaphat Schellekens Jun 04 '15 at 06:46
  • Have you set the JAVA_HOME, and PATH properly? – Yehoshaphat Schellekens Jun 04 '15 at 07:48
  • JAVA_HOME : C:\Program Files\Java\jdk1.8.0_45 JRE_HOME : C:\Program Files\Java\jre1.8.0_45 PATH : %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin;D:\650444\Work\Tools\Octave\Octave3.6.4_gcc4.6.2\bin;C:\Program Files\Java\jdk1.8.0_45\bin;C:\Program Files\Java\jre1.8.0_45\bin\server;D:\Program Files\R\R-3.2.0\bin\x64;D:\Misc\RLib\rJava\jri\x64 – Ayon Jun 04 '15 at 11:52
  • Look at my new answer – Yehoshaphat Schellekens Jun 08 '15 at 04:59
1

You have to initialize properly your Rengine. Try this:

Rengine re = new Rengine (new String [] {"--vanilla"}, false, null);

when you create the engine, and everything should work. The constructor without arguments "create(s) a new engine by hooking into an existing, initialized R instance which is calling this constructor" (from the doc). This causes the error, since there is not an existing Rengine running (I guess).

nicola
  • 24,005
  • 3
  • 35
  • 56
  • 1
    I had tried this previously when I was trying to debug my error. Using this line of code does not throw the stack trace error that i have printed in my question , but the program execution terminates with a return code of 2. Using debugging mode in eclipse i can see it is faling in this Rengine instance creation line. – Ayon Jun 02 '15 at 05:26