I'm executing some R commands from Java using JRI.I want to use the results from R in my Java for further calculations but I have no idea how cast the returned object.
call code in Java:
REXP x;
System.out.println(x = rengine.eval("source(\"/..../TS.R\")"));
System.out.println( x.asVector().elementAt(0));
last line from R code:
eq_all[length(eq_all)-1]
--
output in Java console:
[VECTOR ([REAL* (3.050462038715372)], [BOOLi* ])]
[REAL* (3.050462038715372)]
"3.050462038715372" is the right value but how can I access it in Java?
best regards, Immanuel
PS. related question without answer: Converting REXP object to a double array (Java/R)
I believe
asDouble()
andasDoubleArray()
are what you need.Update: So on your code example, it should be:
PS. The referred question actually had the answer you needed—the problem there is with implementation of
toString()
in Java arrays.elementAt() is not working, your could use at().