diff --git a/NEWS.md b/NEWS.md index 53acf6e84c..7671f25ab4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -69,6 +69,8 @@ rowwiseDT( 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. +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. + ## NOTES 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. diff --git a/R/data.table.R b/R/data.table.R index 8e96095c3c..daf700a589 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -789,7 +789,7 @@ replace_dot_alias = function(e) { tt = eval(bysub, parent.frame(), parent.frame()) if (!is.character(tt)) stopf("by=c(...), key(...) or names(...) must evaluate to 'character'") bysub=tt - } else if (is.call(bysub) && !(bysub[[1L]] %chin% c("list", "as.list", "{", ".", ":"))) { + } else if (is.call(bysub) && !(bysub %iscall% c("list", "as.list", "{", ".", ":"))) { # 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. bysub = as.call(c(as.name('('), list(bysub))) bysubl = as.list.default(bysub) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index b8e28c5cf3..e85d5da778 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -19263,3 +19263,8 @@ df = data.frame(a=1:3) setDT(df) attr(df, "att") = 1 test(2291.1, set(df, NULL, "new", "new"), error="attributes .* have been reassigned") + +# ns-qualified bysub error, #6493 +DT = data.table(a = 1) +test(2292.1, DT[, .N, by=base::mget("a")], data.table(a = 1, N = 1L)) +test(2292.2, DT[, .N, by=base::c("a")], data.table(a = 1, N = 1L))