我尝试使用 Java 代码通过 Rserve 调用 R。我想使用 REXPGenericVector 来存储数组并将其传递给 R:
RList r = new RList();
r.add(new Double(1.0));
REXPGenericVector v = new REXPGenericVector(r);
// make a new local connection on default port (6311)
RConnection c = new RConnection();
// assign data to variable x
c.assign("x",v);
System.out.println("Printing out v:"+v);
但是,错误消息显示在c.assign("x",v);
:
java.lang.ClassCastException: java.lang.Double cannot be cast to org.rosuda.REngine.REXP
at org.rosuda.REngine.RList.at(RList.java:103)
at org.rosuda.REngine.Rserve.protocol.REXPFactory.getBinaryLength(REXPFactory.java:489)
at org.rosuda.REngine.Rserve.RConnection.assign(RConnection.java:272)
at com.xypress.Test.main(Test.java:29)
如何将双精度或字符串或其他类型的数据添加到 RList?
提前致谢。