From be6b797517a15915aa066c23a87d2ebe6af76a57 Mon Sep 17 00:00:00 2001 From: Marco Colombo Date: Thu, 30 Jul 2026 20:56:58 +0200 Subject: [PATCH 1/5] fwrite: Improve validation of the na argument. --- R/fwrite.R | 2 +- inst/tests/tests.Rraw | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/R/fwrite.R b/R/fwrite.R index 5d91b4e347..f62219752a 100644 --- a/R/fwrite.R +++ b/R/fwrite.R @@ -15,7 +15,6 @@ fwrite = function(x, file="", append=FALSE, quote="auto", verbose=getOption("datatable.verbose", FALSE), encoding = "", forceDecimal = FALSE) { - na = as.character(na[1L]) # fix for #1725 if (length(encoding) != 1L || !encoding %chin% c("", "UTF-8", "native")) { stopf("Argument 'encoding' must be '', 'UTF-8' or 'native'.") } @@ -59,6 +58,7 @@ fwrite = function(x, file="", append=FALSE, quote="auto", length(nThread)==1L && !is.na(nThread) && nThread>=1L ) + na = as.character(na[1L]) # fix for #1725 is_gzip = compress == "gzip" || (compress == "auto" && endsWithAny(file, ".gz")) file = path.expand(file) # "~/foo/bar" diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 9d09f5fb0a..f8589ce001 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -10018,6 +10018,7 @@ test(1676.1, fwrite(dt, f, na=NULL), error=base_messages$stopifnot("length(na) = fwrite(dt, f, na=NA) test(1676.2, fread(f), data.table(x=1:2, y=c(NA, "a"))) unlink(f) +test(1676.3, fwrite(dt, na=data.frame()), error=base_messages$stopifnot("length(na) == 1L")) # duplicate names in foverlaps #1730 a = data.table(start = 1:5, end = 2:6, c2 = rnorm(10), c2 = rnorm(10), key=c("start","end")) From 376a942dff76df6ce860865f9d0f59e26aa3015f Mon Sep 17 00:00:00 2001 From: Marco Colombo Date: Thu, 30 Jul 2026 21:13:13 +0200 Subject: [PATCH 2/5] Simplify conversion to character. --- R/fwrite.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/fwrite.R b/R/fwrite.R index f62219752a..d54c480c39 100644 --- a/R/fwrite.R +++ b/R/fwrite.R @@ -58,7 +58,7 @@ fwrite = function(x, file="", append=FALSE, quote="auto", length(nThread)==1L && !is.na(nThread) && nThread>=1L ) - na = as.character(na[1L]) # fix for #1725 + na = as.character(na) # fix for #1725 is_gzip = compress == "gzip" || (compress == "auto" && endsWithAny(file, ".gz")) file = path.expand(file) # "~/foo/bar" From 7949efc2c845f9f3e63add31108b7fcc404a6897 Mon Sep 17 00:00:00 2001 From: Marco Colombo Date: Thu, 30 Jul 2026 21:15:26 +0200 Subject: [PATCH 3/5] Add NEWS. --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index c02a2589fb..eeb77d0590 100644 --- a/NEWS.md +++ b/NEWS.md @@ -82,6 +82,8 @@ 19. `fread()` returns a clearer error message when `dec = NA` is used, [#7737](https://github.com/Rdatatable/data.table/issues/7737). Thanks @mcol for the report and the fix. +20. `fwrite()` returns a clearer error message when `na = data.frame()` is used, [#7866](https://github.com/Rdatatable/data.table/issues/7866). Thanks @mcol for the report and the fix. + ### Notes 1. {data.table} now depends on R 3.5.0 (2018). From a0282053b5ac52a57a95f821c2223359e50f2980 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 30 Jul 2026 14:16:11 -0700 Subject: [PATCH 4/5] preferred min-diff fix --- R/fwrite.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/fwrite.R b/R/fwrite.R index d54c480c39..0e4e2ecaf7 100644 --- a/R/fwrite.R +++ b/R/fwrite.R @@ -15,6 +15,7 @@ fwrite = function(x, file="", append=FALSE, quote="auto", verbose=getOption("datatable.verbose", FALSE), encoding = "", forceDecimal = FALSE) { + na = as.character(na) # fix for #1725 if (length(encoding) != 1L || !encoding %chin% c("", "UTF-8", "native")) { stopf("Argument 'encoding' must be '', 'UTF-8' or 'native'.") } @@ -58,7 +59,6 @@ fwrite = function(x, file="", append=FALSE, quote="auto", length(nThread)==1L && !is.na(nThread) && nThread>=1L ) - na = as.character(na) # fix for #1725 is_gzip = compress == "gzip" || (compress == "auto" && endsWithAny(file, ".gz")) file = path.expand(file) # "~/foo/bar" From 9f3288830bdf3f9b514557aa7bba854001917bc1 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 30 Jul 2026 14:17:11 -0700 Subject: [PATCH 5/5] NEWS entries are 'Notes', not bug fixes --- NEWS.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index eeb77d0590..8b38cf82cb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -80,10 +80,6 @@ 18. `example(local=TRUE)` where the example uses `[.data.table` works again (e.g. `example(':=', package='data.table', local=TRUE, echo=FALSE)`), [#7855](https://github.com/Rdatatable/data.table/issues/7855) re-fixing [#2972](https://github.com/Rdatatable/data.table/issues/2972). Thanks @michaelChirico for the fix. -19. `fread()` returns a clearer error message when `dec = NA` is used, [#7737](https://github.com/Rdatatable/data.table/issues/7737). Thanks @mcol for the report and the fix. - -20. `fwrite()` returns a clearer error message when `na = data.frame()` is used, [#7866](https://github.com/Rdatatable/data.table/issues/7866). Thanks @mcol for the report and the fix. - ### Notes 1. {data.table} now depends on R 3.5.0 (2018). @@ -102,6 +98,10 @@ 8. Clarified `fread()` documentation and vignette regarding the interaction between `keepLeadingZeros = TRUE` and automatic header detection, [#5405](https://github.com/Rdatatable/data.table/issues/5405). Thanks @clemenskuehn for the report and @venom1204 for updating the documentation. +9. `fread()` returns a clearer error message when `dec = NA` is used, [#7737](https://github.com/Rdatatable/data.table/issues/7737). Thanks @mcol for the report and the fix. + +10. `fwrite()` returns a clearer error message when `na = data.frame()` is used, [#7866](https://github.com/Rdatatable/data.table/issues/7866). Thanks @mcol for the report and the fix. + ## data.table [v1.18.4](https://github.com/Rdatatable/data.table/milestone/45) (6 May 2026) ### BUG FIXES