JRI: obtain error messages from the R engine

338 Views Asked by At

I am using JRI to execute a number of computations using the R engine. As pointed in various tutorials out there in the web I am using the eval method of the Rengine class, e.g.:

engine.eval("meanVal=mean(rVector)");

At some point the eval method starts returning NULL, which according to the documentation means "something went wrong". However, I can not identify in the Rengine class a property or a method that would provide an error message, error status or R console output to identify the cause. Is there any way to obtain detailed information on what might be happening?

1

There are 1 best solutions below

3
Simon Urbanek On

It is actually amazingly hard to get error information from R when embedding it. However, it does provide more information at R level. Hence the simplest way is to wrap your code in

try(..., silent=TRUE)

or

tryCatch(..., error=function(e) e)

such that you get errors back to Java by regular evaluation. If you want to get really fancy, you can use Rserve::Rserve.eval() which can also return stack traces on errors but will require the latest version of the Rserve package from http://rforge.net/Rserve