Skip to content
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() applied to 0 variable: different behaviours #5523

Closed
jeremyroos opened this issue Sep 4, 2020 · 0 comments · Fixed by #5533
Closed

across() applied to 0 variable: different behaviours #5523

jeremyroos opened this issue Sep 4, 2020 · 0 comments · Fixed by #5533

Comments

@jeremyroos
Copy link

When across() is applied to 0 variable, it behaves differently depending on whether the tibble contains columns or not:

library(dplyr)

tibble(hello = 1:5) %>% mutate(across(NULL, ~ .x + 1))
# # A tibble: 5 x 1
#   hello
#   <int>
# 1     1
# 2     2
# 3     3
# 4     4
# 5     5

tibble(.rows = 5) %>% mutate(across(NULL, ~ .x + 1))
# Erreur : Problem with `mutate()` input `..1`.
# x Can't select within an unnamed vector.
# i Input `..1` is `across(NULL, ~.x + 1)`.
# Run `rlang::last_error()` to see where the error occurred.

This problem doesn't occur when using scoped verbs:

library(dplyr)

tibble(hello = 1:5) %>% mutate_at(NULL, ~ .x + 1)
# # A tibble: 5 x 1
#   hello
#   <int>
# 1     1
# 2     2
# 3     3
# 4     4
# 5     5

tibble(.rows = 5) %>% mutate_at(NULL, ~ .x + 1)
# # A tibble: 5 x 0

(Version of dplyr: 1.0.2)

romainfrancois added a commit that referenced this issue Sep 17, 2020
romainfrancois added a commit that referenced this issue Oct 14, 2020
* `across()` handles data frames with 0 columns

closes #5523

* additional comment now that r-lib/vctrs#1263 is on dev vctrs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant