diff --git a/src/freadR.c b/src/freadR.c index 035c76eda..9fda821c9 100644 --- a/src/freadR.c +++ b/src/freadR.c @@ -307,7 +307,7 @@ bool userOverride(int8_t *type, lenOff *colNames, const char *anchor, const int else type[i]=CT_DROP; } } - colClassesAs = NULL; + colClassesAs = NULL; // any coercions we can't handle here in C are deferred to R (to handle with methods::as) via this attribute if (length(colClassesSxp)) { SEXP typeRName_sxp = PROTECT(allocVector(STRSXP, NUT)); for (int i=0; incol) { + DTWARN(_("Column number %d (colClasses[[%d]][%d]) is out of range [1,ncol=%d]"), colIdx, i+1, j+1, ncol); + continue; + } + if (type[colIdx-1]<0) { + DTWARN(_("Column %d ('%s') appears more than once in colClasses. The second time is colClasses[[%d]][%d]."), colIdx, CHAR(STRING_ELT(colNamesSxp,colIdx-1)), i+1, j+1); + continue; + } + if (type[colIdx-1] == CT_DROP) { + continue; + } + if (selectRankD) selectRankD[colIdx-1] = rank++; + // NB: mark as negative to indicate 'seen' + if (colClassType == CT_ISO8601_TIME && type[colIdx-1]!=CT_ISO8601_TIME) { + type[colIdx-1] = -CT_STRING; // don't use in-built UTC parser, defer to character and as.POSIXct afterwards which reads in local time + SET_STRING_ELT(colClassesAs, colIdx-1, STRING_ELT(listNames, i)); } else { - if (k>=1 && k<=ncol) { - if (type[k-1]<0) - DTWARN(_("Column %d ('%s') appears more than once in colClasses. The second time is colClasses[[%d]][%d]."), k, CHAR(STRING_ELT(colNamesSxp,k-1)), i+1, j+1); - else if (type[k-1]!=CT_DROP) { - if (thisType==CT_ISO8601_TIME && type[k-1]!=CT_ISO8601_TIME) { - type[k-1] = -CT_STRING; // don't use in-built UTC parser, defer to character and as.POSIXct afterwards which reads in local time - SET_STRING_ELT(colClassesAs, k-1, STRING_ELT(listNames,i)); - } else { - type[k-1] = -thisType; // freadMain checks bump up only not down. Deliberately don't catch here to test freadMain; e.g. test 959 - if (w==NUT) SET_STRING_ELT(colClassesAs, k-1, STRING_ELT(listNames,i)); - } - if (selectRankD) selectRankD[k-1] = rank++; - } - } else { - DTWARN(_("Column number %d (colClasses[[%d]][%d]) is out of range [1,ncol=%d]"), k, i+1, j+1, ncol); - } + type[colIdx-1] = -colClassType; // freadMain checks bump up only not down. Deliberately don't catch here to test freadMain; e.g. test 959 + if (colClassTypeIdx == NUT) SET_STRING_ELT(colClassesAs, colIdx-1, STRING_ELT(listNames, i)); // unknown type --> defer to R } } UNPROTECT(1); // UNPROTECTing itemsInt inside loop to save protection stack } for (int i=0; i drop; reading will proceed in order of columns in file; reorder happens afterwards at R level } UNPROTECT(2); // listNames and typeEnum_idx }