Reputation: 3755
I tried to execute some r code from java using Rserve:
try {
RConnection conn = new RConnection();
conn.eval("write.csv(PoS, file = 'C:/test/PoS.csv',row.names=FALSE)");
} catch (REngineException eR) {
System.err.println("Exception: "+ eR);
throw new TestException("syntax error on eval on R code");
} catch(Exception e){
e.printStackTrace();
throw new TestException("parseAndEval did not generate an exception on syntax error" );
}
I got the eval failed error. But I can successfully execute the Rcode in R:
write.csv(PoS, file = 'C:/test/PoS.csv',row.names=FALSE)
I am sure that Rserve()
has been started on the R side, and other statements like
conn.eval("iris");
is possible.
Upvotes: 2
Views: 4078
Reputation: 10140
To get the proper error message, use this instead of simple eval
REXP rResponseObject = rServeConnection.parseAndEval("try(eval("+R_COMMAND_OR_SOURCE_FILE_PATH+"),silent=TRUE)");
if (rResponseObject.inherits("try-error")) {
LOGGER.error("R Serve Eval Exception : "+rResponseObject.asString());
}
This logger prints exact error thrown from R.
Upvotes: 1
Reputation: 3755
I have solved this issue. The matrix PoS
need to be reloaded, every time I establish a new Rconnection, or save it in the default workspace image alternatively.
Upvotes: 1