From f08a19ed4a41698874557394db8eb7db22503100 Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Tue, 9 Mar 2021 09:51:31 +0100 Subject: [PATCH 1/2] `join_vars()` can handle partially named `on` --- R/step-join.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/step-join.R b/R/step-join.R index f8d0379da..5a9b95fa7 100644 --- a/R/step-join.R +++ b/R/step-join.R @@ -219,7 +219,10 @@ join_is_simple <- function(x, y, by) { } join_vars <- function(x, y, on, suffixes) { - y <- setdiff(y, if (is_named(on)) names(on) else on) + on_y <- names2(on) + on_y[on_y == ""] <- on[on_y == ""] + + y <- setdiff(y, on_y) vars <- union(x, y) both <- intersect(x, y) From 3809a71509ceb792f0041070c8977e4e1e0aa102 Mon Sep 17 00:00:00 2001 From: Maximilian Girlich Date: Tue, 9 Mar 2021 09:52:41 +0100 Subject: [PATCH 2/2] `semi/anti_join()` can handle named `on` --- R/step-join.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/R/step-join.R b/R/step-join.R index 5a9b95fa7..99450f185 100644 --- a/R/step-join.R +++ b/R/step-join.R @@ -34,6 +34,7 @@ dt_call.dtplyr_step_join <- function(x, needs_copy = x$needs_copy) { lhs <- dt_call(x$parent, needs_copy) rhs <- dt_call(x$parent2) on <- call2(".", !!!syms(x$on)) + on <- create_on_call(x$on) by.x <- as.character(x$on) by.y <- ifelse(names(x$on) == "", by.x, names(x$on)) @@ -55,6 +56,15 @@ dt_call.dtplyr_step_join <- function(x, needs_copy = x$needs_copy) { call } +create_on_call <- function(on) { + # names and values have to be swapped in the on call + on_swapped <- set_names(names2(on), on) + on_swapped[on_swapped == ""] <- on[on_swapped == ""] + on_swapped <- simplify_names(on_swapped) + + call2(".", !!!syms(on_swapped)) +} + # dplyr verbs ------------------------------------------------------------- #' Join data tables