Skip to content

Commit

Permalink
feat: Move auto_copy() to avoid error for misplaced copy argument
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Nov 3, 2024
1 parent 5636009 commit e3b23cd
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
3 changes: 1 addition & 2 deletions R/anti_join.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
)
Expand Down
3 changes: 1 addition & 2 deletions R/full_join.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
Expand Down
3 changes: 1 addition & 2 deletions R/inner_join.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
Expand Down
5 changes: 5 additions & 0 deletions R/join.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions R/left_join.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
Expand Down
3 changes: 1 addition & 2 deletions R/right_join.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
Expand Down
3 changes: 1 addition & 2 deletions R/semi_join.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
)
Expand Down

0 comments on commit e3b23cd

Please sign in to comment.