Skip to content

Commit aa879ed

Browse files
Suppressed spurious min/max warnings in cube() internal structure-seeding eval() (#7110)
* suppressed warnings * Clarify NEWS * reference comment * added tests * Update tests.Rraw * correct 2nd test, simplify * fix (ugly) * min->double type --------- Co-authored-by: Michael Chirico <[email protected]>
1 parent 46816e8 commit aa879ed

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
8181
18. Fixed incorrect sorting of merges where the first column of a key is a factor with non-`sort()`-ed levels (e.g. `factor(1:2, 2:1)` and it is joined to a character column, [#5361](https://github.com/Rdatatable/data.table/issues/5361). Thanks to @gbrunick for the report and Benjamin Schwendinger for the fix.
8282
83+
19. Spurious warnings from internal code in `cube()`, `rollup()`, and `groupingsets()` are no longer surfaced to the caller, [#6964](https://github.com/Rdatatable/data.table/issues/6964). Thanks @ferenci-tamas for the report and @venom1204 for the fix.
84+
8385
### NOTES
8486
8587
1. Continued work to remove non-API C functions, [#6180](https://github.com/Rdatatable/data.table/issues/6180). Thanks Ivan Krylov for the PRs and for writing a clear and concise guide about the R API: https://aitap.codeberg.page/R-api/.

R/groupingsets.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ groupingsets.data.table = function(x, j, by, sets, .SDcols, id = FALSE, jj, labe
115115
# inline all arguments that might clash with enclosing environment
116116
pcall = substitute(x[0L, jj, by], list(x = x, jj = jj, by = by))
117117
if (length(.SDcols)) pcall$.SDcols = .SDcols
118-
empty = eval(pcall, list(.datatable.aware = TRUE), enclos)
118+
# suppress e.g. the min(double()) warning, #6964
119+
empty = suppressWarnings(eval(pcall, list(.datatable.aware = TRUE), enclos))
119120
if (id && "grouping" %chin% names(empty)) # `j` could have been evaluated to `grouping` field
120121
stopf("When using `id=TRUE` the 'j' expression must not evaluate to a column named 'grouping'.")
121122
if (anyDuplicated(names(empty)) > 0L)

inst/tests/tests.Rraw

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21347,3 +21347,12 @@ local({
2134721347
test(2326.2, key(d), "x")
2134821348
test(2326.3, indices(d), c("y", "z"))
2134921349
})
21350+
21351+
#6964
21352+
# Test 1: No warning from min() with simple data
21353+
DT = data.table(var = c("a", "b", "c", "d"), value=c(1:3, NA))
21354+
test(2327.1, cube(DT, .(min(value)), "var"),
21355+
data.table(var = c("a", "b", "c", "d", NA), V1 = c(1.0, 2.0, 3.0, NA, NA)))
21356+
test(2327.2, cube(DT, .(as.numeric(base::min(value, na.rm=TRUE))), "var"),
21357+
data.table(var = c("a", "b", "c", "d", NA), V1 = c(1.0, 2.0, 3.0, Inf, 1.0)),
21358+
warning="no non-missing arguments to min")

0 commit comments

Comments
 (0)