我可以从Java调用R并成功从R调用Java函数。 但是,当我尝试使用rJava JRI从R调用Java时,以及Java代码实例新的REngine。报告失败了 R已初始化 然后直接退出R.
我的课程:
public class testRJava {
public void testOK(){
System.out.println("test this funciton could be called OK");
}
public void callSample(){
Rengine re = Rengine.getMainEngine();
if(re == null){
re=new Rengine (new String [] {"--vanilla"}, false, null);
if (!re.waitForR())
{
System.out.println ("Cannot load R");
return;
}
}
// print a random number from uniform distribution
System.out.println (re.eval ("runif(100)").asDouble());
re.end();
}
}
然后,我从R
打电话给Jar> b <- .jnew("testRJava")
> b$testOK()
test this funciton could be called OK
> b$
b$callSample() b$main( b$wait() b$toString() b$getClass() b$notifyAll()
b$testOK() b$wait( b$equals( b$hashCode() b$notify()
> b$callSample()
R is already initialized
[root@ home]#
任何人都知道为什么?有关此错误的任何解决方案
答案 0 :(得分:1)
库(rJava)
.jinit(&#34;&#34)
.jengine(TRUE)
[1]&#34; Java-Object {Thread [Thread-0,5,main]}&#34;
b&lt; - .jnew(&#34; testRJava&#34;)
B $ callSample()