You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we call REngine.eval(REXP what, REXP where, boolean resolve) in Java, and the R command throws an exception (e.g. an explicit stop() or some other unanticipated condition), we currently get an REngineEvalException with the message "error during evaluation". How can we access the error message that R generates?
One technique I've been using goes something like this:
REXP result = null;
try {
result = rengine.parseAndEval(expression);
} catch (REngineException e) {
// The REngineException for a syntax error typically only says "Parse error", so we include the code for context
if (e.getMessage().equals("Parse error"))
throw new REngineException(rengine, "Parse error in R code '" + expression + "'", e);
if (e.getMessage().equals("error during evaluation")) {
List<String> traceback = new ArrayList<>();
for (Object o : rengine.parseAndEval("traceback()").asList()) {
traceback.addAll(java.util.Arrays.asList(((REXPString) o).asStrings()));
}
throw new REngineException(rengine, "error during evaluation of R code:\n" + StringUtils.join(traceback, "\n"), e);
}
throw e;
}
This is fairly brittle, because it depends on the specific error text, etc. Is similar information available somehow from the REngine, or if not, perhaps it could be added?
Thanks.
The text was updated successfully, but these errors were encountered:
If we call
REngine.eval(REXP what, REXP where, boolean resolve)
in Java, and the R command throws an exception (e.g. an explicitstop()
or some other unanticipated condition), we currently get anREngineEvalException
with the message"error during evaluation"
. How can we access the error message that R generates?One technique I've been using goes something like this:
This is fairly brittle, because it depends on the specific error text, etc. Is similar information available somehow from the
REngine
, or if not, perhaps it could be added?Thanks.
The text was updated successfully, but these errors were encountered: