1

I'm using RCaller in Java in order to execute an external R program.

The problem is, that I don't know the exact size of the matrix but the .getAsDoubleMatrix() method wants to have the size.

double[][] matrix = caller.getParser().getAsDoubleMatrix("result", DONT_KNOW, DONT_KNOW);

Is there a way to keep the size dynamic?

Chris
  • 3,057
  • 5
  • 37
  • 63

1 Answers1

0

By the revision e263b5393d43, RoutputParser class has now getDimensions() method for getting unknown dimensions of a matrix. Here is the passed test file:

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]);

the latest compiled jar does not include this update, however, I plan to prepare a version 2.3 next week or you can download the source and compile yourself immediately.

Visit the official blog page of RCaller for the latest release here

jbytecode
  • 681
  • 12
  • 29
  • Well, thanks, so the solution is that there is no solution. :-/ – Chris May 15 '14 at 18:13
  • 1
    Relax! Get the version 2.3.0 which includes the ability that you requested using the link https://drive.google.com/folderview?id=0B-sn_YiTiFLGZUt6d3gteVdjTGM&usp=drive_web – jbytecode May 15 '14 at 18:31
  • And this is the blog entry for the new version: http://stdioe.blogspot.com.tr/2014/05/new-release-rcaller-230_15.html – jbytecode May 15 '14 at 18:52