diff --git a/R/data.table.R b/R/data.table.R index cbba8089cd..47c6729320 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -179,6 +179,8 @@ replace_order = function(isub, verbose, env) { naturaljoin = FALSE if (missing(i) && !missing(on)) { i = eval.parent(.massagei(substitute(on))) + if (!is.list(i) || !length(names(i))) + stop("When on= is provided but not i=, on= must be a named list or data.table|frame, and a natural join (i.e. join on common names) is invoked") naturaljoin = TRUE } if (missing(i) && missing(j)) { @@ -213,7 +215,6 @@ replace_order = function(isub, verbose, env) { if ((isTRUE(which)||is.na(which)) && !missing(j)) stop("which==",which," (meaning return row numbers) but j is also supplied. Either you need row numbers or the result of j, but only one type of result can be returned.") if (!is.na(nomatch) && is.na(which)) stop("which=NA with nomatch=0 would always return an empty vector. Please change or remove either which or nomatch.") if (!with && missing(j)) stop("j must be provided when with=FALSE") - if (missing(i) && !missing(on)) warning("ignoring on= because it is only relevant to i but i is not provided") irows = NULL # Meaning all rows. We avoid creating 1:nrow(x) for efficiency. notjoin = FALSE rightcols = leftcols = integer() diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 323b0368c3..a436e557b4 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -15654,6 +15654,8 @@ X = data.table(a=1:2, b=1:2) test(2076.01, X[on=.(a=2:3, d=2:1)], data.table(a=2:3, b=c(2L,NA_integer_), d=2:1)) Y = data.table(a=2:3, d=2:1) test(2076.02, X[on=Y], data.table(a=2:3, b=c(2L,NA_integer_), d=2:1)) +test(2076.03, X[on=3], error="When on= is provided but not i=, on= must be a named list or data.table|frame, and a natural join") +test(2076.04, X[on=list(3)], error="When on= is provided but not i=, on= must be a named list or data.table|frame, and a natural join") ###################################