Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/fwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ void fwriteMain(fwriteMainArgs args)
for (int j=args.ncol-10; j<args.ncol; j++) DTPRINT(_("%d "), args.whichFun[j]);
}
DTPRINT(_("\nargs.doRowNames=%d args.rowNames=%d doQuote=%d args.nrow=%"PRId64" args.ncol=%d eolLen=%d\n"),
args.doRowNames, args.rowNames, doQuote, (int64_t)args.nrow, args.ncol, eolLen);
args.doRowNames, args.rowNames, doQuote, args.nrow, args.ncol, eolLen);
}

// Calculate upper bound for line length. Numbers use a fixed maximum (e.g. 12 for integer) while strings find the longest
Expand Down Expand Up @@ -788,7 +788,7 @@ void fwriteMain(fwriteMainArgs args)
if (numBatches < nth) nth = numBatches;
if (verbose) {
DTPRINT(_("Writing %"PRId64" rows in %d batches of %d rows (each buffer size %dMB, showProgress=%d, nth=%d)\n"),
(int64_t)args.nrow, numBatches, rowsPerBatch, args.buffMB, args.showProgress, nth);
args.nrow, numBatches, rowsPerBatch, args.buffMB, args.showProgress, nth);
}
t0 = wallclock();

Expand Down Expand Up @@ -921,7 +921,7 @@ void fwriteMain(fwriteMainArgs args)
if (verbose && !hasPrinted) DTPRINT("\n");
DTPRINT("\rWritten %.1f%% of %"PRId64" rows in %d secs using %d thread%s. "
"maxBuffUsed=%d%%. ETA %d secs. ",
(100.0*end)/args.nrow, (int64_t)args.nrow, (int)(now-startTime), nth, nth==1?"":"s",
(100.0*end)/args.nrow, args.nrow, (int)(now-startTime), nth, nth==1?"":"s",
maxBuffUsedPC, ETA);
// TODO: use progress() as in fread
nextTime = now+1;
Expand Down
13 changes: 7 additions & 6 deletions src/fwriteR.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int getStringLen(SEXP *col, int64_t row) {
int getMaxStringLen(const SEXP *col, const int64_t n) {
int max=0;
SEXP last=NULL;
for (int i=0; i<n; ++i) {
for (int64_t i=0; i<n; ++i) {

@mattdowle mattdowle Feb 16, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great spot! Thanks.

SEXP this = *col++;
if (this==last) continue; // no point calling LENGTH() again on the same string; LENGTH is unlikely as fast as single pointer compare
int thisnchar = LENGTH(this);
Expand Down Expand Up @@ -90,17 +90,17 @@ void writeList(SEXP *col, int64_t row, char **pch) {
int getMaxListItemLen(const SEXP *col, const int64_t n) {
int max=0;
SEXP last=NULL;
for (int i=0; i<n; ++i) {
for (int64_t i=0; i<n; ++i) {
SEXP this = *col++;
if (this==last) continue; // no point calling LENGTH() again on the same string; LENGTH is unlikely as fast as single pointer compare
int32_t wf = whichWriter(this);
if (TYPEOF(this)==VECSXP || wf==INT32_MIN || isFactor(this)) {
error(_("Row %d of list column is type '%s' - not yet implemented. fwrite() can write list columns containing items which are atomic vectors of type logical, integer, integer64, double, complex and character."),
error(_("Row %"PRId64" of list column is type '%s' - not yet implemented. fwrite() can write list columns containing items which are atomic vectors of type logical, integer, integer64, double, complex and character."),
i+1, isFactor(this) ? "factor" : type2char(TYPEOF(this)));
}
int width = writerMaxLen[wf];
if (width==0) {
if (wf!=WF_String) STOP(_("Internal error: row %d of list column has no max length method implemented"), i+1); // # nocov
if (wf!=WF_String) STOP(_("Internal error: row %"PRId64" of list column has no max length method implemented"), i+1); // # nocov
const int l = LENGTH(this);
for (int j=0; j<l; ++j) width+=LENGTH(STRING_ELT(this, j));
} else {
Expand Down Expand Up @@ -228,8 +228,9 @@ SEXP fwriteR(
int firstListColumn = 0;
for (int j=0; j<args.ncol; j++) {
SEXP column = VECTOR_ELT(DFcoerced, j);
if (args.nrow != length(column))
error(_("Column %d's length (%d) is not the same as column 1's length (%d)"), j+1, length(column), args.nrow);

@mattdowle mattdowle Feb 16, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great spot too. Yes this would cause that strange number in the error message.

if (args.nrow != length(column)) {
error(_("Column %d's length (%d) is not the same as column 1's length (%"PRId64")"), j+1, length(column), args.nrow);
}
int32_t wf = whichWriter(column);
if (wf<0) {
error(_("Column %d's type is '%s' - not yet implemented in fwrite."), j+1, type2char(TYPEOF(column)));
Expand Down