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:
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):
run
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With