I have a java code and I'm using Rserve to run my R code inside the java. Here is a part of my code:
RConnection c = new RConnection("localhost", 6311);
c.eval("library(e1071)");
c.eval("data(HouseVotes84, package = 'mlbench')";
c.eval("model <- naiveBayes(Class ~ ., data = HouseVotes84)")
REXP t = c.eval("NBC <- model$tables");
List<Double> NBCList = new ArrayList<Double>();
t.asList().add(NBCList);
System.out.println(NBCList);
The problem is that it returns the following:
[]
and the correct output (not using Rserve - directly running on R session) should be:
$V1
V1
Y n y
democrat 0.3953488 0.6046512
republican 0.8121212 0.1878788
$V2
V2
Y n y
democrat 0.4979079 0.5020921
republican 0.4932432 0.5067568
Notice that you have some typos there, please check it in your IDE, also you are not passing correctly data from R to Java.
See the following code of how to use it, this code only passes the
Element of NBC into Java, you'll have to do a lot of Work to pass stuff to java, since R has different types that Java.
See the following Example, notice that i also inserted code that tells you if libraries are correctly installed for Java To use:
Please let me know if that works for you :)