[R] R and/or REngine kills Java

Ralf B ralf.bierig at gmail.com
Wed Mar 24 07:53:06 CET 2010


Hi all,

I am using R and JRI under Windows XP Pro. I am posting this question
here since the reason might be R related (since I am running an R
script) but there is also a very good chance that it is JRI only
(since I am using the JRI interface to activate the script) -- in
which case I want to apologize for misplacing this message.

I have a method that instantiates an REngine object every time it is
called. It runs a script provided by a file name and closes REngine
afterward. The script works fine, the png file is successfully
generated and the PNG file is released so that I can delete it if I
want ( but I don't in that case). For some strange reason, when
running this code twice I get the following error: upon which the Java
Virtual machine dies on me.

 Any explanation would be greatly appreciated!

Best,
Ralf

Here the Java code, the R code, and the Java VM error:

++++++++++++++++ START JAVA CODE ++++++++++++++++++

/** Helper method */
private static void eval(Rengine r, String s) {
	r.eval(s, false);
}
	
/** Assigns the given java value to the given R variable name */
private static void assign(Rengine r, String rVariableName, String javaValue) {
	r.assign(rVariableName, javaValue);
}

public void run() throws Exception {
		String filepath = this.path;
		
		if (filepath != null) {
			File rFile = new File(filepath );
		    if (rFile.exists()) {	// run R script
		    	// start R engine
				if (!Rengine.versionCheck()) {
					System.err.println("** Version mismatch - Java files don't match
library version.");
					System.exit(1);
				}
				// creating R engine
				Rengine rEngine = new Rengine(null, false, new EmptyCallbacks());
				// the engine creates R is a new thread, so we should wait until it's ready
				if (!rEngine.waitForR()) {
					System.out.println("Cannot load R for " + this.getClass().getName());
					return;
				}

				// executing logic
				try {
					assign(rEngine, "filename", filepath);
					eval(rEngine, "source(filename)");
				} catch (Exception e) {
					System.out.println(this.getClass().getName() + ": Error in R code: " + e);
					e.printStackTrace();
					// stopping R engine
					System.out.println("Error when running script - rEngine stopped!");
					if (rEngine != null){
						rEngine.end();
					}
				}

				// stopping R engine
				rEngine.end();
		    } else {
		    	throw new Exception(getClass().getName() + " not run - missing
R file - location: " + rFile.getAbsolutePath());
		    }
		}
	}

+++++++++++++++++++++ END JAVA CODE +++++++++++++++++++++++++


+++++ START  R Code ++++++++
library(RJDBC)

# db connection
driver <- JDBC("com.mysql.jdbc.Driver","lib/mysql-connector-java-5.0.6-bin.jar")
con <- dbConnect(driver, "jdbc:mysql://localhost/mydb", "xxx", "yyy")

# list tables
dbListTables(con)

# user, task and event information
result = dbGetQuery(con, "SELECT x,y from mytable;")
png(file="output.png")
plot(result$x, result$y)
dev.off()

+++++ START  R Code ++++++++

ERROR:

#
# An unexpected error has been detected by Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=...., pid=5400, tid=3204
#
# Java VM: Java HotSpot(TM) Client VM (11.2-b01 mixed mode, ....)
# Problematic frame:
# C  [R.dll+0x1136fe]
#

# An error report file with more information is saved as:
# ....
[WARN] 404 - GET /output.png (127.0.0.1) 1402 bytes
   Request headers
      Host: localhost:8888
      User-Agent: ....
      Accept: image/png,image/*;q=0.8,*/*;q=0.5
      Accept-Language: en-us,en;q=0.5
      Accept-Encoding: gzip,deflate
      Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
      Keep-Alive: 115
      Connection: keep-alive
      Referer: http://localhost....
   Response headers
      Content-Length: 1402
      Content-Type: text/html; charset=iso-8859-1
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#



More information about the R-help mailing list