Skip to content

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

Description

@jeremyroos

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)

Activity

  1. added a commit that references this issue on Sep 17, 2020
    5cc776e
  2. added a commit that references this issue on Oct 14, 2020
    c1e6496
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions