Skip to content

Commit

Permalink
Merge pull request #775 from markfairbanks/simplify-check_across
Browse files Browse the repository at this point in the history
Simplify `check_no_across()`
  • Loading branch information
markfairbanks authored Oct 21, 2023
2 parents 59abd07 + ef4ab8e commit 3a1fd5e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion R/distinct.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ distinct <- function(.df, ..., .keep_all = FALSE) {
distinct.tidytable <- function(.df, ..., .keep_all = FALSE) {
dots <- enquos(...)

check_across(dots, "distinct")
check_no_across(dots)

if (length(dots) == 0) {
out <- vec_unique(.df)
Expand Down
2 changes: 1 addition & 1 deletion R/group_by.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ group_by <- function(.df, ..., .add = FALSE) {
#' @export
group_by.tidytable <- function(.df, ..., .add = FALSE) {
dots <- enquos(...)
check_across(dots, "group_by")
check_no_across(dots)
.groups <- tidyselect_names(.df, !!!dots)
if (length(.groups) == 0) {
out <- .df
Expand Down
2 changes: 1 addition & 1 deletion R/mutate.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ mutate.tidytable <- function(.df, ..., .by = NULL,
one_dot <- length(dots) == 1

if (!one_dot) {
is_across <- map_lgl(dots[-1], quo_is_call, c("across.", "across"))
is_across <- map_lgl(dots[-1], quo_is_call, "across")
if (any(is_across)) {
# tidyselect helpers will miss columns made before an across call
# that is not in the first position
Expand Down
9 changes: 5 additions & 4 deletions R/utils-general.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ vec_ptype_compatible <- function(x, y) {
tryCatch({vec_ptype_common(x, y); TRUE}, error = function(e) FALSE)
}

check_across <- function(dots, .fn) {
uses_across <- any(map_lgl(dots, quo_is_call, c("across", "across.", "pick")))

if (uses_across) {
check_no_across <- function(dots) {
any_across <- any(map_lgl(dots, quo_is_call, c("across", "pick")))
if (any_across) {
.fn <- as.character(caller_call()[[1]])
.fn <- str_replace(.fn, ".tidytable", "")
msg <- glue("`across()`/`pick()` are unnecessary in `{.fn}()`.
Please directly use tidyselect.
Ex: df %>% {.fn}(where(is.numeric))")
Expand Down

0 comments on commit 3a1fd5e

Please sign in to comment.