Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Join by named vector #223

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion R/step-join.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -219,7 +229,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)
Expand Down