Setting up Java R Interface (JRI) on Windows

前端 未结 2 1158
旧巷少年郎
旧巷少年郎 2020-12-18 11:15

I have followed guides on the web and looked at questions on stackoverflow but I am still not able to set up JRI on Windows.

Here are the steps I have taken:

2条回答
  •  佛祖请我去吃肉
    2020-12-18 11:39

    Latest (2018) for me was to do this :-

    export R_HOME=$(R RHOME)
    

    Then compile this:-

    String[] enginargs = {"--no-save"};
    REngine engine = org.rosuda.REngine.JRI.JRIEngine.createEngine(enginargs, null, false);
    
    try {
        engine.parseAndEval("print(\"Hello from R\");");
    }
    catch(Exception e ) {
        System.err.println("OOps:-" + e.getMessage());
    }
    finally {
        engine.close();
    }
    

    Then when running the java either set the LD_LIBRARY_PATH to enclude JRI or set the -Djava.library.path eg

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/R/site-library/rJava/jri/
    

    or

    java -Djava.library.path=/usr/local/lib/R/site-library/rJava/jri/ MyMainClass
    

提交回复
热议问题