您好,我正在根据本网站上的说明设置储备。 http://www.codophile.com/how-to-integrate-r-with-java-using-rserve/
但是在 Eclipse 中使用“eval”时出现错误
double d[] = c.eval("rnorm(10)").asDoubles();
错误 - “RConnection 类型的方法 eval(String) 未定义”
JAR 已正确加载到构建路径中,并且 rserve 正在运行,但是我无法弄清楚为什么只有 eval 函数导致了问题。
除此之外,还导入...
import org.rosuda.REngine.Rserve.RConnection;
导致错误 - “导入 org.rosuda.REngine.Rserve.RConnection 与同一文件中定义的类型冲突”
有谁知道为什么会出现这种情况吗?谢谢
所有进口:
import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;
public class RConnection {
public int[] mean(String a[]) {
setupR();
return null;
}
public void setupR(){
try {
/* Create a connection to Rserve instance running
* on default port 6311
*/
RConnection c = new RConnection();// make a new local connection on default port (6311)
double d[] = c.eval("rnorm(10)").asDoubles();
org.rosuda.REngine.REXP x0 = c.eval("R.version.string");
System.out.println(x0.asString());
} catch (RserveException e) {
e.printStackTrace();
} catch (REXPMismatchException e) {
e.printStackTrace();
}
}
}
最佳答案
通过使用import org.rosuda.REngine.Rserve.RConnection;
,您需要使RConnection
在本地命名空间中已知。
但是,您已经在本地定义了一个名为 RConnection
的类。
请重命名您的类RConnection
,您应该能够导入org.rosuda.REngine.Rserve.RConnection
。
关于java - 保留 - Eclipse 和 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34383150/