Reputation: 1
I am using rServe to integrate R and Java. I'm able to call R function from Java and that function returns summary of variable. But the problem is I am unable to display that summary in Java. Below is the snippet of Java code I'm using.
RConnection c = new RConnection();
c.eval("library(ggplot)");
REXP desc = c.eval("describe(mpg)");
System.out.println(desc.asString());
describe function in R gives following output.
describe(mpg)
mpg
11 Variables 234 Observations
--------------------------------------------------------------------------
manufacturer
n missing distinct
234 0 15
audi (18, 0.077), chevrolet (19, 0.081), dodge (37, 0.158), ford (25,
0.107), honda (9, 0.038), hyundai (14, 0.060), jeep (8, 0.034), land
rover (4, 0.017), lincoln (3, 0.013), mercury (4, 0.017), nissan (13,
0.056), pontiac (5, 0.021), subaru (14, 0.060), toyota (34, 0.145)
Upvotes: 0
Views: 535
Reputation: 339
The way that I capture my R output in java is:
String ret = c.eval("paste(capture.output(describe(mpg))),collapse='\\n')").asString();
System.out.print(ret);
Upvotes: 1