From 0874a2db1e4e3928e28786d9f21869fb43b301e1 Mon Sep 17 00:00:00 2001 From: Jan Gorecki Date: Thu, 26 Feb 2026 11:07:17 +0600 Subject: [PATCH 1/3] Fix frollapply to handle n > len case --- R/frollapply.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/frollapply.R b/R/frollapply.R index 9c1b0c26d..6a138547d 100644 --- a/R/frollapply.R +++ b/R/frollapply.R @@ -278,8 +278,11 @@ frollapply = function(X, N, FUN, ..., by.column=TRUE, fill=NA, align=c("right"," cpy = copy ansMask = function(len, n) { mask = rep(TRUE, len) - if (n) ## handle n==0 + if (n) { ## handle n==0 + if (n > len) + n = len + 1L ## bugfix #7646 mask[seq_len(n-1L)] = FALSE + } mask } tight0 = function(i, dest, src, n) FUN(dest, ...) ## skip memcpy when n==0 From 4a537ee28f14dae83d69ceac9dcafd91f9007b42 Mon Sep 17 00:00:00 2001 From: Jan Gorecki Date: Thu, 26 Feb 2026 11:10:15 +0600 Subject: [PATCH 2/3] unit test for bugfix --- inst/tests/froll.Rraw | 3 +++ 1 file changed, 3 insertions(+) diff --git a/inst/tests/froll.Rraw b/inst/tests/froll.Rraw index 5f8225910..22fd88423 100644 --- a/inst/tests/froll.Rraw +++ b/inst/tests/froll.Rraw @@ -2317,3 +2317,6 @@ test(6015.907, frolladapt(c(1L,3L,2L), 2L), error="be sorted, have no duplicates test(6015.908, frolladapt(c(1L,2L,2L), 2L), error="be sorted, have no duplicates, have no NAs") test(6015.909, frolladapt(c(1L,2L,NA_integer_), 2L), error="be sorted, have no duplicates, have no NAs") ## loop that checks for sorted will detect NAs as well, except for first element test(6015.910, frolladapt(c(NA_integer_,1L,2L), 2L), error="be sorted, have no duplicates, have no NAs") ## first NA is detected by extra check + +# frollapply can produce output longer than the input when the window-length is also longer than the input #7646 +test(6100.1, frollapply(c(1,2,3,4,5),N=7,FUN=sum), rep(NA, 5L)) From 281ab78f591b0434ce8b8964c9fa410836467195 Mon Sep 17 00:00:00 2001 From: Jan Gorecki Date: Thu, 26 Feb 2026 11:12:51 +0600 Subject: [PATCH 3/3] news entry --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 7cf63f0b7..d781f90e1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -40,6 +40,8 @@ 5. Non-equi joins combining an equality condition with two inequality conditions on the same column (e.g., `on = .(id == id, val >= lo, val <= hi)`) no longer error, [#7641](https://github.com/Rdatatable/data.table/issues/7641). The internal `chmatchdup` remapping of duplicate `rightcols` was overwriting the original column indices, causing downstream code to reference non-existent columns. Thanks @tarun-t for the report and fix, and @aitap for the diagnosis. +6. `frollapply()` could have produce output longer than the input when the window-length is also longer than the input [#7646](https://github.com/Rdatatable/data.table/issues/7646). Thanks to @hadley-johnson for reporting and @jangorecki for the fix. + ### Notes 1. {data.table} now depends on R 3.5.0 (2018).