Skip to content
Snippets Groups Projects
Commit 85a25ab1 authored by Mick Jordan's avatar Mick Jordan
Browse files

fix WriteTable for RFactor

parent dc92e90d
Branches
No related tags found
No related merge requests found
...@@ -34,7 +34,7 @@ public class WriteTable { ...@@ -34,7 +34,7 @@ public class WriteTable {
/* handle factors internally, check integrity */ /* handle factors internally, check integrity */
RStringVector[] levels = new RStringVector[nc]; RStringVector[] levels = new RStringVector[nc];
for (int j = 0; j < nc; j++) { for (int j = 0; j < nc; j++) {
RAbstractVector xj = (RAbstractVector) x.getDataAtAsObject(j); RAbstractContainer xj = (RAbstractContainer) x.getDataAtAsObject(j);
if (xj.getLength() != nr) { if (xj.getLength() != nr) {
throw new IllegalArgumentException("corrupt data frame -- length of column " + (j + 1) + " does not not match nrows"); throw new IllegalArgumentException("corrupt data frame -- length of column " + (j + 1) + " does not not match nrows");
} }
...@@ -51,23 +51,16 @@ public class WriteTable { ...@@ -51,23 +51,16 @@ public class WriteTable {
os.write(csep.getBytes()); os.write(csep.getBytes());
} }
for (int j = 0; j < nc; j++) { for (int j = 0; j < nc; j++) {
RAbstractVector xj = (RAbstractVector) x.getDataAtAsObject(j); RAbstractContainer xj = (RAbstractContainer) x.getDataAtAsObject(j);
if (j > 0) if (j > 0)
os.write(csep.getBytes()); os.write(csep.getBytes());
if (isna(xj, i)) { if (isna(xj, i)) {
tmp = cna; tmp = cna;
} else { } else {
if (levels[j] != null) { if (levels[j] != null) {
/* tmp = encodeElement2(levels[j], (int) xj.getDataAtAsObject(i) - 1, quoteCol[j], qmethod, cdec);
* We do not assume factors have integer levels, although they should.
*/
if (xj instanceof RIntVector || xj instanceof RDoubleVector) {
tmp = encodeElement2(levels[j], (int) xj.getDataAtAsObject(i) - 1, quoteCol[j], qmethod, cdec);
} else {
throw new IllegalArgumentException("column " + (j + 1) + " claims to be a factor but does not have numeric codes");
}
} else { } else {
tmp = encodeElement2(xj, i, quoteCol[j], qmethod, cdec); tmp = encodeElement2((RAbstractVector) xj, i, quoteCol[j], qmethod, cdec);
} }
/* if(cdec) change_dec(tmp, cdec, TYPEOF(xj)); */ /* if(cdec) change_dec(tmp, cdec, TYPEOF(xj)); */
} }
...@@ -138,7 +131,7 @@ public class WriteTable { ...@@ -138,7 +131,7 @@ public class WriteTable {
return encodeElement(x, indx, quote ? '"' : 0, cdec); return encodeElement(x, indx, quote ? '"' : 0, cdec);
} }
private static boolean isna(RAbstractVector x, int indx) { private static boolean isna(RAbstractContainer x, int indx) {
if (x instanceof RLogicalVector) { if (x instanceof RLogicalVector) {
return RRuntime.isNA(((RLogicalVector) x).getDataAt(indx)); return RRuntime.isNA(((RLogicalVector) x).getDataAt(indx));
} else if (x instanceof RDoubleVector) { } else if (x instanceof RDoubleVector) {
...@@ -161,7 +154,7 @@ public class WriteTable { ...@@ -161,7 +154,7 @@ public class WriteTable {
throw RInternalError.unimplemented(); throw RInternalError.unimplemented();
} }
private static boolean isFactor(RAbstractVector v) { private static boolean isFactor(RAbstractContainer v) {
for (int i = 0; i < v.getClassHierarchy().getLength(); i++) { for (int i = 0; i < v.getClassHierarchy().getLength(); i++) {
if (v.getClassHierarchy().getDataAt(i).equals("factor")) { if (v.getClassHierarchy().getDataAt(i).equals("factor")) {
return true; return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment