Skip to content

Commit 2d2b55b

Browse files
author
AJ Montanez
committed
Made .NATURAL unpacked enough for columns to be dected for joining.
1 parent 64f5525 commit 2d2b55b

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454

5555
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.
5656

57+
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.
58+
59+
5760
### Notes
5861

5962
1. {data.table} now depends on R 3.5.0 (2018).

R/data.table.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,10 +845,14 @@ replace_dot_alias = function(e) {
845845
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.")
846846
}
847847
} else if (identical(substitute(on), as.name(".NATURAL"))) {
848-
naturaljoin = TRUE
849-
}
848+
common_names = intersect(names_x, names(i))
849+
if (!length(common_names))
850+
stopf("Attempting to do natural join but no common columns in provided tables")
851+
on = common_names
852+
}
850853
if (naturaljoin) { # natural join #629
851854
common_names = intersect(names_x, names(i))
855+
print(common_names)
852856
len_common_names = length(common_names)
853857
if (!len_common_names) stopf("Attempting to do natural join but no common columns in provided tables")
854858
if (verbose) {

0 commit comments

Comments
 (0)