diff --git a/NEWS.md b/NEWS.md index 698ce99b6..63debb2fb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -54,6 +54,9 @@ 10. `fread()` no longer misreads dates with negative years, [#7704](https://github.com/Rdatatable/data.table/issues/7704). Thanks to @kevinushey for the report and @aitap for the fix. +11. `.NAUTRAL` now unpacks early enough to detect common columns, the same as `on=` join, [#6667] (https://github.com/Rdatatable/data.table/issues/6667). Thanks you @MichaelChirico for the report and @aam936 for the fix. + + ### Notes 1. {data.table} now depends on R 3.5.0 (2018). diff --git a/R/data.table.R b/R/data.table.R index a989538b1..b97ee40b0 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -845,10 +845,14 @@ replace_dot_alias = function(e) { stopf("When i is a data.table (or character vector), the columns to join by must be specified using the 'on=' argument (see ?data.table); by keying x (i.e., x is sorted and marked as such, see ?setkey); or by using 'on = .NATURAL' to indicate using the shared column names between x and i (i.e., a natural join). Keyed joins might have further speed benefits on very large data due to x being sorted in RAM.") } } else if (identical(substitute(on), as.name(".NATURAL"))) { - naturaljoin = TRUE - } + common_names = intersect(names_x, names(i)) + if (!length(common_names)) + stopf("Attempting to do natural join but no common columns in provided tables") + on = common_names + } if (naturaljoin) { # natural join #629 common_names = intersect(names_x, names(i)) + print(common_names) len_common_names = length(common_names) if (!len_common_names) stopf("Attempting to do natural join but no common columns in provided tables") if (verbose) {