2

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.

1
  • @Kevin yes, File path is correct Commented Aug 18, 2015 at 21:18

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.