We are working on a complex statistical project on Java. We did the original code in the R programming language. Is there a way to convert this code to Ja
As @Seidr said, using rJava we can run R code directly from Java methods.
Open R console and install rJava package
install.packages("rJava")
Now you will find rJava in "R home\library"
Now in eclipse, add JRI.jar, JRIEngine.jar, REngine.jar to project build path. These jars are available in "R home\library\rJava\jri"
Now create two vectors, add them and store in another variable. Now print that result variable in console.
Rengine engine = new Rengine(new String[]{"--no-save"},false,null);
String aVector = "c(1,2,3)";
String bVector = "c(4,5,6)";
engine.eval("a<-"+aVector);
engine.eval("b<-"+bVector);
engine.eval("c<-a+b");
System.out.println("Sum of two vectors : c = "+engine.eval("c"));
Hope below link helps (step-by-step procedure to integrate R in Java).
http://www.codophile.com/how-to-integrate-r-with-java-using-rjava/