diff --git a/NEWS.md b/NEWS.md index 97e1f41b0..4236e8b07 100644 --- a/NEWS.md +++ b/NEWS.md @@ -113,6 +113,8 @@ rowwiseDT( 14. `setDT()` no longer modifies the class of other names bound to the origin data.frame, e.g., in `DF1 <- data.frame(a=1); DF2 <- DF1; setDT(DF2)`, `DF1`'s class will not change. [#4784](https://github.com/Rdatatable/data.table/issues/4784). Thanks @OfekShilon for the report and fix. +15. `DT[1, on=NULL]` now works for returning the first row, [#6579](https://github.com/Rdatatable/data.table/issues/6579). Thanks to @Kodiologist for the report and @tdhock for the PR. + ## 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 1c2c07a3f..62210bd83 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -587,7 +587,7 @@ replace_dot_alias = function(e) { } } else { - if (!missing(on)) { + if (!is.null(on)) { stopf("logical error. i is not a data.table, but 'on' argument is provided.") } # TO DO: TODO: Incorporate which_ here on DT[!i] where i is logical. Should avoid i = !i (above) - inefficient. @@ -1498,7 +1498,7 @@ replace_dot_alias = function(e) { if (byjoin) { # The groupings come instead from each row of the i data.table. # Much faster for a few known groups vs a 'by' for all followed by a subset - if (!is.data.table(i)) stopf("logical error. i is not data.table, but mult='all' and 'by'=.EACHI") + if (!is.data.table(i)) stopf("logical error. i is not a data.table, but mult='all' and 'by'=.EACHI") byval = i bynames = if (missing(on)) head(key(x),length(leftcols)) else names(on) allbyvars = NULL diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 2e90de1ba..d68130255 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -13909,7 +13909,9 @@ test(1967.48, x[ , b, .SDcols = 'a'], 6:10, warning = "This j doesn't use .SD") test(1967.49, x[ , list(5) := 6], error = 'LHS of := must be a symbol') test(1967.50, x[ , 1 + 3i := 6], error = "LHS of := isn't column names") -test(1967.511, x[ , .(5L), by = .EACHI, mult = 'all'], error='logical error. i is not data.table') +test(1967.511, x[ , .(5L), by = .EACHI, mult = 'all'], error='logical error. i is not a data.table') +test(1967.5111, x[1, on="a"], error='logical error. i is not a data.table') +test(1967.5112, x[1, on=NULL], x[1]) #6579 test(1967.512, x[1+3i], error='i has evaluated to type complex. Expecting logical, integer or double') test(1967.521, x[1:2, by=a], x[1:2,], warning="Ignoring by/keyby because 'j' is not supplied") test(1967.522, x[, by=a], x, warning=c("Ignoring by/keyby because 'j' is not supplied","i and j are both missing.*upgraded to error in future"))