JAVA调用R脚本 windwos路径下

       RConnection c = new RConnection();
// REXP x = c.eval("source('D:\\\\jiaoben\\\\RJava_test.R',encoding = \"UTF-8\")");
REXP x = c.eval("source('D:\\\\jiaoben\\\\Rjava_testx6.R',encoding = \"UTF-8\")");
// REXP eval = c.eval("running()");
REXP eval = c.eval("iscompleted()");
System.out.println(eval.asString());



脚本内容

library(Rserve)
Rserve()

Sys.sleep(5)
message("The Task is Finished Successfully!")

iscompleted <- function(){
return("The Task is Finished Successfully!")
}

    如果R连接拒绝,要在R中开启Rserve  

              打开Rstudio后会出现JAVA调用不了脚本的情况,关了就好了,待大家发掘

网上关于windows路径的资料太少,试验了好久

posted @ 2018-12-22 14:04  渔阳nice  阅读(370)  评论(0编辑  收藏  举报