Skip to content

Commit 9443409

Browse files
Use %iscall% to handle more general by= inputs correctly (#6499)
1 parent 8f505d5 commit 9443409

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ rowwiseDT(
6969

7070
11. `fread()` automatically detects timestamps with sub-second accuracy again, [#6440](https://github.com/Rdatatable/data.table/issues/6440). This was a regression due to interference with new `dec='auto'` support. Thanks @kav2k for the concise report and @MichaelChirico for the fix.
7171

72+
12. Using a namespace-qualified call on the RHS of `by=`, e.g. `DT[,.N,by=base::mget(v)]`, works again, fixing [#6493](https://github.com/Rdatatable/data.table/issues/6493). Thanks to @mmoisse for the report and @MichaelChirico for the fix.
73+
7274
## NOTES
7375

7476
1. Tests run again when some Suggests packages are missing, [#6411](https://github.com/Rdatatable/data.table/issues/6411). Thanks @aadler for the note and @MichaelChirico for the fix.

R/data.table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ replace_dot_alias = function(e) {
789789
tt = eval(bysub, parent.frame(), parent.frame())
790790
if (!is.character(tt)) stopf("by=c(...), key(...) or names(...) must evaluate to 'character'")
791791
bysub=tt
792-
} else if (is.call(bysub) && !(bysub[[1L]] %chin% c("list", "as.list", "{", ".", ":"))) {
792+
} else if (is.call(bysub) && !(bysub %iscall% c("list", "as.list", "{", ".", ":"))) {
793793
# potential use of function, ex: by=month(date). catch it and wrap with "(", because we need to set "bysameorder" to FALSE as we don't know if the function will return ordered results just because "date" is ordered. Fixes #2670.
794794
bysub = as.call(c(as.name('('), list(bysub)))
795795
bysubl = as.list.default(bysub)

inst/tests/tests.Rraw

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19263,3 +19263,8 @@ df = data.frame(a=1:3)
1926319263
setDT(df)
1926419264
attr(df, "att") = 1
1926519265
test(2291.1, set(df, NULL, "new", "new"), error="attributes .* have been reassigned")
19266+
19267+
# ns-qualified bysub error, #6493
19268+
DT = data.table(a = 1)
19269+
test(2292.1, DT[, .N, by=base::mget("a")], data.table(a = 1, N = 1L))
19270+
test(2292.2, DT[, .N, by=base::c("a")], data.table(a = 1, N = 1L))

0 commit comments

Comments
 (0)