using R programming in java

后端 未结 4 1670
一向
一向 2020-12-25 13:11

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

相关标签:
4条回答
  • 2020-12-25 13:35

    As @Seidr said, using rJava we can run R code directly from Java methods.

    1. Open R console and install rJava package

      install.packages("rJava")
      

      Now you will find rJava in "R home\library"

    2. Now in eclipse, add JRI.jar, JRIEngine.jar, REngine.jar to project build path. These jars are available in "R home\library\rJava\jri"

    3. Create Rengine object.
    4. 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/

    0 讨论(0)
  • 2020-12-25 13:38

    The another option to run R on JVM is FastR. According FastR's documentation:

    FastR is an implementation of the R Language in Java atop Truffle, a framework for building self-optimizing AST interpreters.

    FastR is currently available in two forms:

    • As a pre-built binary with the Truffle implementations of Ruby and JavaScript for Linux and Mac OS X. Unfortunately, there is no Windows version available yet.
    • As a source release on GitHub. This option does not come with Ruby or JavaScript.
    0 讨论(0)
  • 2020-12-25 13:40

    While I'm unaware of a 'converter', there is an interface called rJava which will allow you to run R code directly from Java.

    http://www.rforge.net/rJava/

    rJava is a simple R-to-Java interface. It is comparable to the .C/.Call C interface. rJava provides a low-level bridge between R and Java (via JNI). It allows to create objects, call methods and access fields of Java objects from R.

    In a sense the inverse of rJava is JRI (Java/R Interface) which provides the opposite direction - calling R from Java. JRI is now shipped as a part of the rJava package, although it still can be used as a separate entity (especially for development). Currently rJava is used as a part of JGR, iPlots and JavaGD software/packages.

    0 讨论(0)
  • 2020-12-25 13:49

    You can try Renjin (http://www.renjin.org):

    "Renjin is a JVM-based interpreter for the R language for statistical computing. This project is an initiative of BeDataDriven, a company providing consulting in analytics and decision support systems."

    0 讨论(0)
提交回复
热议问题