我在 Java 中使用 RCaller 来执行外部 R 程序。
问题是,我不知道矩阵的确切大小,但该.getAsDoubleMatrix()
方法想要具有大小。
double[][] matrix = caller.getParser().getAsDoubleMatrix("result", DONT_KNOW, DONT_KNOW);
有没有办法保持大小动态?
通过修订 e263b5393d43,RoutputParser 类现在具有 getDimensions() 方法,用于获取矩阵的未知维度。这是通过的测试文件:
int n = 21;
int m = 23;
double[][] data = new double[n][m];
for (int i=0;i<data.lengthi++){
for (int j=0;j<data[0].length;j++){
data[i][j] = Math.random();
}
}
RCaller caller = new RCaller();
Globals.detect_current_rscript();
caller.setRscriptExecutable(Globals.Rscript_current);
RCode code = new RCode();
code.addDoubleMatrix("x", data);
caller.setRCode(code);
caller.runAndReturnResult("x");
int[] mydim = caller.getParser().getDimensions("x");
Assert.assertEquals(n, mydim[0]);
Assert.assertEquals(m, mydim[1]);
最新编译的jar不包括这个更新,不过我打算下周准备2.3版本或者你可以下载源码自己编译。
在此处访问 RCaller 的官方博客页面以获取最新版本