如何发送带有R脚本的Android应用程序,并确保它执行

时间:2016-03-26 06:58:02

标签: java android r machine-learning

我正在构建一个Android机器学习应用程序,在java类中我需要调用R脚本。但在此之前,我需要确保R已启动并运行。我怎么做?如何在Android代码中建立Rconnection?

  public String getSum() {
    RConnection connection = null;

    try {
        /* Create a connection to Rserve instance running on default port
         * 6311
         */
        connection = new RConnection();
        connection.eval("library(randomForest)");
        /* Note four slashes (\\\\) in the path */
        connection.eval("source('MyScript.R')");

        REXP sum =connection.eval("predictSAL()");
        this.sum = sum.asString();
    } catch (RserveException e) {
        e.printStackTrace();
    } catch (REXPMismatchException e) {
        e.printStackTrace();
    } catch (REngineException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return sum;
}

0 个答案:

没有答案