0

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?

Luís de Sousa
  • 5,765
  • 11
  • 49
  • 86

1 Answers1

0

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

Simon Urbanek
  • 13,842
  • 45
  • 45
  • That code is not Java, but in any case, the `engine.eval()` method is not issuing exceptions. As I wrote in the question, the only clue of a problem is this method returning `NULL`. – Luís de Sousa Mar 13 '17 at 07:35
  • Exactly, that's why I was pointing out that you want to catch it in the R side - see above - as you can't on the the Java side since R won't give you that unless you ask. – Simon Urbanek Mar 16 '17 at 20:25
  • Now I understand it must be the code passed to `engine.eval()` to be wrapped; you might wish to edit you answer to make it clearer. In any case, this way I get `[NULL]` instead of just `NULL`. – Luís de Sousa Mar 17 '17 at 15:59