0

I have an R script that retrieves data from a database, performs some operations on it and provides me with data I want to retrive in Java using JRI

beforeQuery <- c(1)
query <- {{Query}}
....
queryResult <- fetch(queryResultSet,1)

The Java code that gets the result:

re.eval("source('" + location + "')"); //location of the R script
System.out.println(re.eval("beforeQuery").asString()); //works
System.out.println(re.eval("queryResult$column").asString()); //returns null

I have verified that queryResult is okay by running the R program standalone.

What can I do to make sure that I can get the result inside the java program successfully?

punitjajodia
  • 92
  • 1
  • 7

1 Answers1

0

You need to pass the re.eval() method into an REXP variable and then transfer it into a Java string with .asString(), like that:

REXP test =  re.eval("head(queryResult$column,100)");
   String [] output = test.asString();
 for (i = 0; i < test.length  ; i++) {System.out.println(output[i]);}

Notice that as mentioned in JRI and ARIMA integration , there is a limit for the amount of data you can pass from R to Java, that's why I've added "head", to check if it works. if it does, then just remove it.

Community
  • 1
  • 1
Yehoshaphat Schellekens
  • 2,305
  • 2
  • 22
  • 49