diff --git a/inst/tests/issue_3400_fread.txt b/inst/tests/issue_3400_fread.txt new file mode 100644 index 0000000000..17b2ee2f61 Binary files /dev/null and b/inst/tests/issue_3400_fread.txt differ diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 3b4de02461..e6cb6615f2 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -14008,6 +14008,9 @@ DT = data.table(x=c("a","b","c","b","a","c"), y=c(1,3,6,1,6,3), v=1:6) setindex(DT, y) test(2024, DT[y==6, v:=10L, verbose=TRUE], output=c("Constructing irows for.*", "Reorder irows for.*")) +# fread embedded NULL, #3400 +test(2025, fread(testDir("issue_3400_fread.txt"), skip=1, header=TRUE), data.table(A=INT(1,3), B=INT(2,2), C=INT(3,1))) + ################################### # Add new tests above this line # diff --git a/src/fread.c b/src/fread.c index 7543f98078..3e05f97583 100644 --- a/src/fread.c +++ b/src/fread.c @@ -2149,7 +2149,10 @@ int freadMain(freadMainArgs _args) { while (*tch==' ') tch++; // multiple sep=' ' at the tLineStart does not mean sep. We're at tLineStart because the fast branch above doesn't run when sep=' ' fieldStart = tch; skip_white(&tch); - if (*tch=='\0') continue; // empty last line + if (*tch=='\0') { + nrowLimit = myNrow; + continue; // empty last line + } if (eol(&tch) && skipEmptyLines) { tch++; continue; } tch = fieldStart; // in case tabs at the beginning of the first field need to be included }