-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
across()
confuses function name with column name
#6545
Comments
It seems like .fns don't like the column name being same as the r base function... But change mean function as ~ mean(.) works well... library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
tibble(sd = 1:5) %>%
summarize(across(.fns = sd))
#> Error in `summarize()`:
#> ! Problem while computing `..1 = across(.fns = sd)`.
#> Caused by error:
#> ! attempt to select less than one element in integerOneIndex
#> Backtrace:
#> ▆
#> 1. ├─tibble(sd = 1:5) %>% summarize(across(.fns = sd))
#> 2. ├─dplyr::summarize(., across(.fns = sd))
#> 3. ├─dplyr:::summarise.data.frame(., across(.fns = sd))
#> 4. │ └─dplyr:::summarise_cols(.data, dplyr_quosures(...), caller_env = caller_env())
#> 5. │ ├─base::withCallingHandlers(...)
#> 6. │ └─dplyr:::expand_across(dots[[i]])
#> 7. │ ├─dplyr:::across_setup(...)
#> 8. │ └─rlang::eval_tidy(expr$.fns, mask, env = env)
#> 9. ├─`<fn>`()
#> 10. └─base::.handleSimpleError(...)
#> 11. └─dplyr (local) h(simpleError(msg, call))
#> 12. └─rlang::abort(bullets, call = error_call, parent = skip_internal_condition(e))
tibble(mean = 1:5) %>%
summarize(across(.fns = ~mean(.)))
#> # A tibble: 1 × 1
#> mean
#> <dbl>
#> 1 3 Created on 2022-11-18 with reprex v2.0.2 |
lionel-
added a commit
that referenced
this issue
Nov 18, 2022
lionel-
added a commit
that referenced
this issue
Dec 16, 2022
lionel-
added a commit
that referenced
this issue
Dec 22, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apparently, any function whose name appears as a column name of a tibble cannot be used within
across()
even when it is specified as the.fns
argument:Created on 2022-11-17 with reprex v2.0.2
Session info
The text was updated successfully, but these errors were encountered: