Skip to content

Commit afa87e1

Browse files
authored
check on=NULL instead of missing for error when i is not a data.table (#6581)
1 parent e5b845e commit afa87e1

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

NEWS.md

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

114114
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.
115115
116+
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.
117+
116118
## NOTES
117119
118120
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ replace_dot_alias = function(e) {
587587
}
588588
}
589589
else {
590-
if (!missing(on)) {
590+
if (!is.null(on)) {
591591
stopf("logical error. i is not a data.table, but 'on' argument is provided.")
592592
}
593593
# 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) {
14981498
if (byjoin) {
14991499
# The groupings come instead from each row of the i data.table.
15001500
# Much faster for a few known groups vs a 'by' for all followed by a subset
1501-
if (!is.data.table(i)) stopf("logical error. i is not data.table, but mult='all' and 'by'=.EACHI")
1501+
if (!is.data.table(i)) stopf("logical error. i is not a data.table, but mult='all' and 'by'=.EACHI")
15021502
byval = i
15031503
bynames = if (missing(on)) head(key(x),length(leftcols)) else names(on)
15041504
allbyvars = NULL

inst/tests/tests.Rraw

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13909,7 +13909,9 @@ test(1967.48, x[ , b, .SDcols = 'a'], 6:10,
1390913909
warning = "This j doesn't use .SD")
1391013910
test(1967.49, x[ , list(5) := 6], error = 'LHS of := must be a symbol')
1391113911
test(1967.50, x[ , 1 + 3i := 6], error = "LHS of := isn't column names")
13912-
test(1967.511, x[ , .(5L), by = .EACHI, mult = 'all'], error='logical error. i is not data.table')
13912+
test(1967.511, x[ , .(5L), by = .EACHI, mult = 'all'], error='logical error. i is not a data.table')
13913+
test(1967.5111, x[1, on="a"], error='logical error. i is not a data.table')
13914+
test(1967.5112, x[1, on=NULL], x[1]) #6579
1391313915
test(1967.512, x[1+3i], error='i has evaluated to type complex. Expecting logical, integer or double')
1391413916
test(1967.521, x[1:2, by=a], x[1:2,], warning="Ignoring by/keyby because 'j' is not supplied")
1391513917
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"))

0 commit comments

Comments
 (0)