diff --git a/R/anti_join.R b/R/anti_join.R index 5801b310..dfb51d99 100644 --- a/R/anti_join.R +++ b/R/anti_join.R @@ -9,7 +9,7 @@ anti_join.duckplyr_df <- function(x, y, by = NULL, copy = FALSE, ..., na_matches na_matches <- check_na_matches(na_matches, error_call = error_call) # Our implementation - rel_try(call = list(name = "anti_join", x = x, y = y, args = list(by = if(!is.null(by)) as_join_by(by), copy = copy, na_matches = na_matches)), + rel_try(call = 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)), { out <- rel_join_impl(x, y, by, "anti", na_matches, error_call = error_call) return(out) diff --git a/R/count.R b/R/count.R index ab4d26a0..8e76fc03 100644 --- a/R/count.R +++ b/R/count.R @@ -11,20 +11,18 @@ count.duckplyr_df <- function(x, ..., wt = NULL, sort = FALSE, name = NULL, .dro by_exprs <- unname(map(by, quo_get_expr)) is_name <- map_lgl(by_exprs, is_symbol) - rel_try(call = list(name = "count", x = x, args = list(dots = enquos(...), wt = enquo(wt), sort = sort, name = if (!is.null(name)) sym(name), .drop = .drop)), + by_chr <- map_chr(by_exprs, as_string) + name_was_null <- is.null(name) + name <- check_n_name(name, by_chr, call = dplyr_error_call()) + + n <- tally_n(x, {{ wt }}) + + rel_try(call = list(name = "count", x = x, args = list(dots = enquos(...), wt = enquo(wt), sort = sort, name = if (!name_was_null) sym(name), .drop = .drop)), "count() needs all(is_name)" = !all(is_name), "count() only implemented for .drop = TRUE" = !.drop, "count() only implemented for sort = FALSE" = sort, + "Name clash in count()" = (name %in% by_chr), { - by_chr <- map_chr(by_exprs, as_string) - name <- check_n_name(name, by_chr) - - if (name %in% by_chr) { - cli::cli_abort("Name clash in `count()`") - } - - n <- tally_n(x, {{ wt }}) - rel <- duckdb_rel_from_df(x) groups <- rel_translate_dots(by, x) diff --git a/R/full_join.R b/R/full_join.R index 63b3fdaf..afd19875 100644 --- a/R/full_join.R +++ b/R/full_join.R @@ -6,7 +6,7 @@ full_join.duckplyr_df <- function(x, y, by = NULL, copy = FALSE, suffix = c(".x" y <- auto_copy(x, y, copy = copy) # Our implementation - rel_try(call = list(name = "full_join", x = x, y = y, args = list(by = if(!is.null(by)) as_join_by(by), copy = copy, keep = keep, na_matches = na_matches, multiple = multiple, relationship = relationship)), + rel_try(call = 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) diff --git a/R/inner_join.R b/R/inner_join.R index 48e82a1d..000e6e0d 100644 --- a/R/inner_join.R +++ b/R/inner_join.R @@ -6,7 +6,7 @@ inner_join.duckplyr_df <- function(x, y, by = NULL, copy = FALSE, suffix = c(".x y <- auto_copy(x, y, copy = copy) # Our implementation - rel_try(call = list(name = "inner_join", x = x, y = y, args = list(by = if(!is.null(by)) as_join_by(by), copy = copy, keep = keep, na_matches = na_matches, multiple = multiple, unmatched = unmatched, relationship = relationship)), + rel_try(call = 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) diff --git a/R/left_join.R b/R/left_join.R index aec81a64..c527d647 100644 --- a/R/left_join.R +++ b/R/left_join.R @@ -6,7 +6,7 @@ left_join.duckplyr_df <- function(x, y, by = NULL, copy = FALSE, suffix = c(".x" y <- auto_copy(x, y, copy = copy) # Our implementation - rel_try(call = list(name = "left_join", x = x, y = y, args = list(by = if(!is.null(by)) as_join_by(by), copy = copy, keep = keep, na_matches = na_matches, multiple = multiple, unmatched = unmatched, relationship = relationship)), + rel_try(call = 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) diff --git a/R/relational.R b/R/relational.R index 09aa016a..c866bc1d 100644 --- a/R/relational.R +++ b/R/relational.R @@ -8,6 +8,10 @@ rel_try <- function(rel, ..., call = NULL) { stats$attempts <- stats$attempts + 1L + if (Sys.getenv("DUCKPLYR_TELEMETRY_PREP_TEST") == "TRUE") { + force(call) + } + if (Sys.getenv("DUCKPLYR_TELEMETRY_TEST") == "TRUE") { force(call) json <- call_to_json( diff --git a/R/right_join.R b/R/right_join.R index 49380684..01cf7594 100644 --- a/R/right_join.R +++ b/R/right_join.R @@ -6,7 +6,7 @@ right_join.duckplyr_df <- function(x, y, by = NULL, copy = FALSE, suffix = c(".x y <- auto_copy(x, y, copy = copy) # Our implementation - rel_try(call = list(name = "right_join", x = x, y = y, args = list(by = if(!is.null(by)) as_join_by(by), copy = copy, keep = keep, na_matches = na_matches, multiple = multiple, unmatched = unmatched, relationship = relationship)), + rel_try(call = 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) diff --git a/R/semi_join.R b/R/semi_join.R index 2dccf2a4..843447ec 100644 --- a/R/semi_join.R +++ b/R/semi_join.R @@ -9,7 +9,7 @@ semi_join.duckplyr_df <- function(x, y, by = NULL, copy = FALSE, ..., na_matches na_matches <- check_na_matches(na_matches, error_call = error_call) # Our implementation - rel_try(call = list(name = "semi_join", x = x, y = y, args = list(by = if(!is.null(by)) as_join_by(by), copy = copy, na_matches = na_matches)), + rel_try(call = 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)), { out <- rel_join_impl(x, y, by, "semi", na_matches, error_call = error_call) return(out) diff --git a/tests/testthat/_snaps/count-tally.md b/tests/testthat/_snaps/count-tally.md index ff4287fa..ef6d7812 100644 --- a/tests/testthat/_snaps/count-tally.md +++ b/tests/testthat/_snaps/count-tally.md @@ -3,7 +3,7 @@ Code duckplyr_count(df, x, name = 1) Condition - Error in `tally()`: + Error in `count()`: ! `name` must be a single string, not the number 1. --- @@ -11,7 +11,7 @@ Code duckplyr_count(df, x, name = letters) Condition - Error in `tally()`: + Error in `count()`: ! `name` must be a single string, not a character vector. # can only explicitly chain together multiple tallies @@ -45,11 +45,9 @@ Code (expect_error(duckplyr_count(mtcars, new = 1 + ""))) Output - - Error in `group_by()`: - i In argument: `new = 1 + ""`. - Caused by error in `1 + ""`: - ! non-numeric argument to binary operator + + Error in `FUN()`: + ! Can't convert a call to a string. Code (expect_error(duckplyr_count(mtcars, wt = 1 + ""))) Output diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 46d415d9..23da2852 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -6,6 +6,8 @@ withr::local_envvar(DUCKPLYR_FALLBACK_COLLECT = 0, .local_envir = testthat::tear withr::local_envvar(DUCKPLYR_OUTPUT_ORDER = TRUE, .local_envir = testthat::teardown_env()) +# withr::local_envvar(DUCKPLYR_TELEMETRY_PREP_TEST = TRUE, .local_envir = testthat::teardown_env()) + # withr::local_envvar(DUCKPLYR_FORCE = TRUE, .local_envir = testthat::teardown_env()) withr::defer(envir = testthat::teardown_env(), {