Skip to content

Commit

Permalink
Closes #1384. fread handles empty lines with just spaces correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Oct 11, 2015
1 parent 3398e5d commit d75728f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@

12. `merge.data.table` always resets class to `c("data.table", "data.frame")` in result to be consistent with `merge.data.frame`, [#1378](https://github.com/Rdatatable/data.table/issues/1378). Thanks @ladida771.

13. `fread` reads text input with empty newline but with just spaces properly, for e.g., fread('a,b\n1,2\n '), [#1384](https://github.com/Rdatatable/data.table/issues/1384). Thanks to @ladida771.

#### NOTES


Expand Down
5 changes: 5 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -7047,6 +7047,11 @@ test(1571, names(tstrsplit(X$a, "", fixed=TRUE, give.names=TRUE)), paste("V", 1:
test(1572, fread('"abcd efgh." ijkl.\tmnop "qrst uvwx."\t45\n', quote=""),
setDT(read.table(text='"abcd efgh." ijkl.\tmnop "qrst uvwx."\t45\n', sep="\t", stringsAsFactors=FALSE, quote="")))

# Fix for #1384, fread with empty new line, initial checks failed due to extra spaces.
test(1573, fread('a,b
1,2
'), data.table(a=1L, b=2L))

##########################


Expand Down
3 changes: 2 additions & 1 deletion src/fread.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ SEXP readfile(SEXP input, SEXP separg, SEXP nrowsarg, SEXP headerarg, SEXP nastr
case 1: ch = pos + 1*(eof-pos)/3; str="+ middle"; break;
case 2: ch = pos + 2*(eof-pos)/3; str="+ last"; break; // 2/3 way through rather than end ... easier
}
if (j) {
if (j) {
// we may have landed inside quoted field containing embedded sep and/or embedded \n
// find next \n and see if 5 good lines follow. If not try next \n, and so on, until we find the real \n
// We don't know which line number this is because we jumped straight to it
Expand Down Expand Up @@ -1041,6 +1041,7 @@ SEXP readfile(SEXP input, SEXP separg, SEXP nrowsarg, SEXP headerarg, SEXP nastr
}
while (ch<eof && *ch!=eol) ch++;
if (ch<eof && *ch==eol) ch+=eolLen;
if (stripWhite) skip_spaces();
}
if (verbose) { Rprintf("Type codes (%s 5 rows): ",str); for (i=0; i<ncol; i++) Rprintf("%d",type[i]); Rprintf("\n"); }
}
Expand Down

0 comments on commit d75728f

Please sign in to comment.