From 6dec6e3399f6a6bd042eb503b65c9c3a643bd4eb Mon Sep 17 00:00:00 2001 From: Luke Shahan Date: Tue, 17 Nov 2026 10:08:21 -0700 Subject: [PATCH 1/4] fread: parse quoted numeric fields containing whitespace --- NEWS.md | 2 ++ inst/tests/tests.Rraw | 4 ++++ src/fread.c | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/NEWS.md b/NEWS.md index f74eed63a8..b913134aa0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -96,6 +96,8 @@ 21. GForce grouping is again faster when running single-threaded, e.g. after `setDTthreads(1)`, [#3330](https://github.com/Rdatatable/data.table/issues/3330). The batching used to parallelize `gsum()` and `gmean()` is skipped when only one thread is available. Also, `mean()` of an `integer` or `logical` column by group no longer coerces the whole column to `double` first, which made it slower than in v1.12.0 regardless of the number of threads. Thanks @jangorecki for the benchmarks, @mattdowle for the report, and @ben-schwen for the fix. +22. `fread()` parses quoted numbers with leading or trailing whitespace as numeric rather than character, matching `read.table()` behavior, [#PR]. Thanks @loganb7869 for the PR. + ### Notes 1. {data.table} now depends on R 3.5.0 (2018). diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 4277ed1533..951e8fef87 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -22016,3 +22016,7 @@ test(2388.24, nafill(c("a", NA, NA, "z"), type="nocb", limit=1), c("a", NA, "z", x = seq(as.IDate("1999-01-01"), as.IDate("2027-12-31"), by="day") test(2389.1, isoweek(x), as.integer(format(x, "%V"))) test(2389.2, isoyear(x), as.integer(format(x, "%G"))) +test(2390.1, fread('"a";"b"\n"x";" 123"\n"y";" 456"\n"z";" 789"', sep=";"), data.table(a=c("x", "y", "z"), b=c(123L, 456L, 789L))) +test(2390.2, fread('"a";"b"\n"x";"123 "\n"y";"456 "\n"z";"789 "', sep=";"), data.table(a=c("x", "y", "z"), b=c(123L, 456L, 789L))) +test(2390.3, fread('"a";"b"\n"x";" 12.5 "\n"y";" 45.6 "', sep=";"), data.table(a=c("x", "y"), b=c(12.5, 45.6))) +test(2390.4, fread('"a";"b"\n" abc ";123\n" def ";456', sep=";"), data.table(a=c(" abc ", " def "), b=c(123L, 456L))) \ No newline at end of file diff --git a/src/fread.c b/src/fread.c index d9aab52da5..8f047838d6 100644 --- a/src/fread.c +++ b/src/fread.c @@ -1344,7 +1344,9 @@ static int detect_types(const char **pch, int ncol, bool *bumped) } if (*ch == quote && quote) { // && quote to exclude quote='\0' (user passed quote="") ch++; + skip_white(&ch); fun[tmpType[field]](&fctx); + skip_white(&ch); if (*ch == quote) { ch++; skip_white(&ch); @@ -2685,10 +2687,12 @@ int freadMain(freadMainArgs _args) if (!end_of_field(tch)) tch = afterSpace; // else it is the field_end, we're on closing sep|eol and we'll let processor write appropriate NA as if field was empty if (*tch == quote && quote) { quoted = true; tch++; } } // else Field() handles NA inside it unlike other processors e.g. ,, is interpreted as "" or NA depending on option read inside Field() + if (quoted) skip_white(&tch); fun[IGNORE_BUMP(thisType)](&fctx); bool typeBump = false; if (quoted) { // quoted was only set to true with '&& quote' above (=> quote!='\0' now) + skip_white(&tch); if (*tch == quote) tch++; else typeBump = true; } From 8d9b4f8c316e34733f57ebec48ba50fd0717ca68 Mon Sep 17 00:00:00 2001 From: Luke Shahan Date: Tue, 17 Nov 2026 10:27:20 -0700 Subject: [PATCH 2/4] Update NEWS.md with PR link --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index b913134aa0..0b9bd32b44 100644 --- a/NEWS.md +++ b/NEWS.md @@ -96,7 +96,7 @@ 21. GForce grouping is again faster when running single-threaded, e.g. after `setDTthreads(1)`, [#3330](https://github.com/Rdatatable/data.table/issues/3330). The batching used to parallelize `gsum()` and `gmean()` is skipped when only one thread is available. Also, `mean()` of an `integer` or `logical` column by group no longer coerces the whole column to `double` first, which made it slower than in v1.12.0 regardless of the number of threads. Thanks @jangorecki for the benchmarks, @mattdowle for the report, and @ben-schwen for the fix. -22. `fread()` parses quoted numbers with leading or trailing whitespace as numeric rather than character, matching `read.table()` behavior, [#PR]. Thanks @loganb7869 for the PR. +22. `fread()` parses quoted numbers with leading or trailing whitespace as numeric rather than character, matching `read.table()` behavior, [#7962](https://github.com/Rdatatable/data.table/pull/7962). Thanks @loganb7869 for the PR. ### Notes From 2bbf478a8589b1f98427c4de15d6263fab6c3780 Mon Sep 17 00:00:00 2001 From: Ivan K Date: Sun, 29 Nov 2026 22:58:18 +0300 Subject: [PATCH 3/4] Tentative fix for the NEWS entry --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 0b9bd32b44..3519b66078 100644 --- a/NEWS.md +++ b/NEWS.md @@ -96,7 +96,7 @@ 21. GForce grouping is again faster when running single-threaded, e.g. after `setDTthreads(1)`, [#3330](https://github.com/Rdatatable/data.table/issues/3330). The batching used to parallelize `gsum()` and `gmean()` is skipped when only one thread is available. Also, `mean()` of an `integer` or `logical` column by group no longer coerces the whole column to `double` first, which made it slower than in v1.12.0 regardless of the number of threads. Thanks @jangorecki for the benchmarks, @mattdowle for the report, and @ben-schwen for the fix. -22. `fread()` parses quoted numbers with leading or trailing whitespace as numeric rather than character, matching `read.table()` behavior, [#7962](https://github.com/Rdatatable/data.table/pull/7962). Thanks @loganb7869 for the PR. +22. `fread()` parses quoted numbers with leading or trailing whitespace as numeric rather than character, matching `read.table()` behavior, [#7946](https://github.com/Rdatatable/data.table/issues/7946). Thanks @CCIAABZ for the report and @loganb7869, @lds295 for the PR. ### Notes From fac8ca22e0e1851dd42fab577c18194c76b478cb Mon Sep 17 00:00:00 2001 From: Ivan K Date: Sun, 29 Nov 2026 23:03:32 +0300 Subject: [PATCH 4/4] Fix NEWS entry --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 3519b66078..4a2b099cba 100644 --- a/NEWS.md +++ b/NEWS.md @@ -96,7 +96,7 @@ 21. GForce grouping is again faster when running single-threaded, e.g. after `setDTthreads(1)`, [#3330](https://github.com/Rdatatable/data.table/issues/3330). The batching used to parallelize `gsum()` and `gmean()` is skipped when only one thread is available. Also, `mean()` of an `integer` or `logical` column by group no longer coerces the whole column to `double` first, which made it slower than in v1.12.0 regardless of the number of threads. Thanks @jangorecki for the benchmarks, @mattdowle for the report, and @ben-schwen for the fix. -22. `fread()` parses quoted numbers with leading or trailing whitespace as numeric rather than character, matching `read.table()` behavior, [#7946](https://github.com/Rdatatable/data.table/issues/7946). Thanks @CCIAABZ for the report and @loganb7869, @lds295 for the PR. +22. `fread()` parses quoted numbers with leading or trailing whitespace as numeric rather than character, matching `read.table()` behavior, [#7946](https://github.com/Rdatatable/data.table/issues/7946). Thanks @CCIAABZ for the report and @loganb7869, @lds295, @DiamondCat106 for the PR. ### Notes