简体   繁体   中英

Rserve Exception “eval failed, request status: error code: 127”

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM