RConnection connection = null;
/* Create a connection to Rserve instance running on default port
* 6311
*/
try{
/* Create a connection to Rserve instance running
* on default port 6311
*/
connection = new RConnection();
/* Note four slashes (\\\\) in the path */
connection.eval("source('E:\\\\MyScript.R')");
REXP sum =connection.parseAndEval("try(eval(predictSAL()),silent=TRUE)");
System.out.println("The sum is=" + sum.asString());
} catch (RserveException e) {
e.printStackTrace();
} catch (REXPMismatchException e) {
e.printStackTrace();
} catch (REngineException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我试图在java中执行此代码。在此处调用R脚本导致一个错误找不到函数randomForest
。在R控制台中第一次出现相同的错误。但后来我执行了install.packages(randomForest
)和库(randomFroest),然后它开始正常工作。但是当从java调用时它仍然无效。我是否需要在任何地方做出更多改变?