DataFrame { public static DataFrame create(int n, int m) { return new DataFrame(DataFrameUtil.createEmptyObjectsMatrix(n,m), DataFrameUtil.createDefaultNamesArray(n)); } private  DataFrame(Object[][] objects, String[] names); static DataFrame create(int n, int m); static DataFrame create(Object[][] objects, String[] names); Object[] getColumn(int i); Object[] getRow(int i); Object[][] getObjects(); String[] getNames(); int getNumberOfColumns(); int getNumberOfRows(); Object getObject(int n, int m);  }
@Test(expected = IllegalArgumentException.class) public void createDataFrameTest_shouldFail() { Object[][] objects = new Object[][]{{1,2,3}, {"a", "b", "c"}}; String[] names = new String[] {"numbers"}; DataFrame.create(objects, names); }
@Test public void writeDataFrameToRAndGetMean() { Object[][] objects = new Object[][]{{1, 2, 3, 4}, {2, 3, 4, 5}, {3, 4, 5, 6}}; DataFrame dataFrame = DataFrame.create(objects, DataFrameUtil.createDefaultNamesArray(3)); RCaller rCaller = RCaller.create(); RCode rCode = RCode.create(); rCode.addDataFrame("df", dataFrame); rCode.addRCode("result <- c(colMeans(df), rowMeans(df))"); rCaller.setRCode(rCode); rCaller.runAndReturnResult("result"); double[] result = rCaller.getParser().getAsDoubleArray("result"); assertEquals(result[0], 2.5); assertEquals(result[1], 3.5); assertEquals(result[2], 4.5); assertEquals(result[3], 2.0); assertEquals(result[4], 3.0); assertEquals(result[5], 4.0); assertEquals(result[6], 5.0); }
@Test public void writeBigDataFrame() { RCaller rCaller = RCaller.create(); RCode rCode = RCode.create(); rCode.addDataFrame("df", DataFrame.create(DataFrameUtil.createObjectsMatrix(2000, 3000, 2), DataFrameUtil.createDefaultNamesArray(2000))); rCode.addRCode("result <- c(nrow(df), ncol(df), df[2,2])"); rCaller.setRCode(rCode); rCaller.runAndReturnResult("result"); double[] result = rCaller.getParser().getAsDoubleArray("result"); assertEquals(result[0], 3000d); assertEquals(result[1], 2000d); assertEquals(result[2], 2d); }