From e3b23cdb0fe71cdfd84a99817312ebb5ea8c3b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 3 Nov 2024 06:19:47 +0100 Subject: [PATCH] feat: Move `auto_copy()` to avoid error for misplaced `copy` argument --- R/anti_join.R | 3 +-- R/full_join.R | 3 +-- R/inner_join.R | 3 +-- R/join.R | 5 +++++ R/left_join.R | 3 +-- R/right_join.R | 3 +-- R/semi_join.R | 3 +-- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/R/anti_join.R b/R/anti_join.R index 1414cac95..d2b3ee26b 100644 --- a/R/anti_join.R +++ b/R/anti_join.R @@ -3,7 +3,6 @@ anti_join.duckplyr_df <- function(x, y, by = NULL, copy = FALSE, ..., na_matches = c("na", "never")) { check_dots_empty0(...) error_call <- caller_env() - y <- auto_copy(x, y, copy = copy) # https://github.com/duckdb/duckdb/issues/6597 na_matches <- check_na_matches(na_matches, error_call = error_call) @@ -12,7 +11,7 @@ anti_join.duckplyr_df <- function(x, y, by = NULL, copy = FALSE, ..., na_matches rel_try(list(name = "anti_join", x = x, y = y, args = list(by = if (!is.null(by) && !is_cross_by(by)) as_join_by(by), copy = copy, na_matches = na_matches)), "No restrictions" = FALSE, { - out <- rel_join_impl(x, y, by, "anti", na_matches, error_call = error_call) + out <- rel_join_impl(x, y, by, copy, "anti", na_matches, error_call = error_call) return(out) } ) diff --git a/R/full_join.R b/R/full_join.R index efce308ec..fe4c69914 100644 --- a/R/full_join.R +++ b/R/full_join.R @@ -3,13 +3,12 @@ full_join.duckplyr_df <- function(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = NULL, na_matches = c("na", "never"), multiple = "all", relationship = NULL) { check_dots_empty0(...) error_call <- caller_env() - y <- auto_copy(x, y, copy = copy) # Our implementation rel_try(list(name = "full_join", x = x, y = y, args = list(by = if (!is.null(by) && !is_cross_by(by)) as_join_by(by), copy = copy, keep = keep, na_matches = na_matches, multiple = multiple, relationship = relationship)), "No implicit cross joins for full_join()" = is_cross_by(by), { - out <- rel_join_impl(x, y, by, "full", na_matches, suffix, keep, error_call) + out <- rel_join_impl(x, y, by, copy, "full", na_matches, suffix, keep, error_call) return(out) } ) diff --git a/R/inner_join.R b/R/inner_join.R index 0c410409c..f45edef9d 100644 --- a/R/inner_join.R +++ b/R/inner_join.R @@ -3,13 +3,12 @@ inner_join.duckplyr_df <- function(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = NULL, na_matches = c("na", "never"), multiple = "all", unmatched = "drop", relationship = NULL) { check_dots_empty0(...) error_call <- caller_env() - y <- auto_copy(x, y, copy = copy) # Our implementation rel_try(list(name = "inner_join", x = x, y = y, args = list(by = if (!is.null(by) && !is_cross_by(by)) as_join_by(by), copy = copy, keep = keep, na_matches = na_matches, multiple = multiple, unmatched = unmatched, relationship = relationship)), "No implicit cross joins for inner_join()" = is_cross_by(by), { - out <- rel_join_impl(x, y, by, "inner", na_matches, suffix, keep, error_call) + out <- rel_join_impl(x, y, by, copy, "inner", na_matches, suffix, keep, error_call) return(out) } ) diff --git a/R/join.R b/R/join.R index fd2810a07..ba06bfbf3 100644 --- a/R/join.R +++ b/R/join.R @@ -2,12 +2,17 @@ rel_join_impl <- function( x, y, by, + copy, join, na_matches, suffix = c(".x", ".y"), keep = NULL, error_call = caller_env() ) { + # Forcing copy might be an error, fall back in this case + # Examples: joyn, gtsummary, crosshap + y <- auto_copy(x, y, copy = copy) + mutating <- !(join %in% c("semi", "anti")) if (mutating) { diff --git a/R/left_join.R b/R/left_join.R index 1576a8363..801d3d3d2 100644 --- a/R/left_join.R +++ b/R/left_join.R @@ -3,13 +3,12 @@ left_join.duckplyr_df <- function(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = NULL, na_matches = c("na", "never"), multiple = "all", unmatched = "drop", relationship = NULL) { check_dots_empty0(...) error_call <- caller_env() - y <- auto_copy(x, y, copy = copy) # Our implementation rel_try(list(name = "left_join", x = x, y = y, args = list(by = if (!is.null(by) && !is_cross_by(by)) as_join_by(by), copy = copy, keep = keep, na_matches = na_matches, multiple = multiple, unmatched = unmatched, relationship = relationship)), "No implicit cross joins for left_join()" = is_cross_by(by), { - out <- rel_join_impl(x, y, by, "left", na_matches, suffix, keep, error_call) + out <- rel_join_impl(x, y, by, copy, "left", na_matches, suffix, keep, error_call) return(out) } ) diff --git a/R/right_join.R b/R/right_join.R index 439d557c5..7c16d6136 100644 --- a/R/right_join.R +++ b/R/right_join.R @@ -3,13 +3,12 @@ right_join.duckplyr_df <- function(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = NULL, na_matches = c("na", "never"), multiple = "all", unmatched = "drop", relationship = NULL) { check_dots_empty0(...) error_call <- caller_env() - y <- auto_copy(x, y, copy = copy) # Our implementation rel_try(list(name = "right_join", x = x, y = y, args = list(by = if (!is.null(by) && !is_cross_by(by)) as_join_by(by), copy = copy, keep = keep, na_matches = na_matches, multiple = multiple, unmatched = unmatched, relationship = relationship)), "No implicit cross joins for right_join()" = is_cross_by(by), { - out <- rel_join_impl(x, y, by, "right", na_matches, suffix, keep, error_call) + out <- rel_join_impl(x, y, by, copy, "right", na_matches, suffix, keep, error_call) return(out) } ) diff --git a/R/semi_join.R b/R/semi_join.R index eb1dfb0bc..0dede5fc6 100644 --- a/R/semi_join.R +++ b/R/semi_join.R @@ -3,7 +3,6 @@ semi_join.duckplyr_df <- function(x, y, by = NULL, copy = FALSE, ..., na_matches = c("na", "never")) { check_dots_empty0(...) error_call <- caller_env() - y <- auto_copy(x, y, copy = copy) # https://github.com/duckdb/duckdb/issues/6597 na_matches <- check_na_matches(na_matches, error_call = error_call) @@ -12,7 +11,7 @@ semi_join.duckplyr_df <- function(x, y, by = NULL, copy = FALSE, ..., na_matches rel_try(list(name = "semi_join", x = x, y = y, args = list(by = if (!is.null(by) && !is_cross_by(by)) as_join_by(by), copy = copy, na_matches = na_matches)), "No restrictions" = FALSE, { - out <- rel_join_impl(x, y, by, "semi", na_matches, error_call = error_call) + out <- rel_join_impl(x, y, by, copy, "semi", na_matches, error_call = error_call) return(out) } )