JRI - Checking for type of returned value from R script

593 Views Asked by At

I am using JRI and calling R script from Java. The R script returns an integer. Following is how I am calling the R script -

REXP result = rengine.eval("source(\"" + [script name with path] + "\")");

REXP retVal = rengine.eval(getReturnVariable());

Following is the relevant code in the R script -

retVal<-sum(num1, num2)

return(as.integer(retVal))

The calling Java code should be able to call any R script. The script could be returning various data-types and so I need to look at the return type in order to extract the result.

In the calling Java program, when I check 'retVal', I see that there are the following 2 attributes -

  1. rtype - which is set to 13 (INTSXP)
  2. Xt - which is returned by gettype() - which is set to 32 (XT_ARRAY_INT)

My question is - which of the above type should the calling program look at?

Also any pointers to any mappings between R and Java data types would help.

I have also looked at the following posting, but could not understand the actual solution to the above query - call-r-from-java-using-jri-how-to-cast-return-value

Regards, ~Milind

0

There are 0 best solutions below