Skip to content

Select and relocate work inconsistenly on an empty dataframe #6167

Description

@jttoivon

I expect that trying to relocate a non-existing column with any_of would return the original dataframe. Even if the dataframe is empty. The function select seems to work more consistently with any_of.

My dplyr version is 1.0.7.

library(tidyverse)
tibble(a=1:2) %>% relocate(any_of("b"))
#> # A tibble: 2 × 1
#>       a
#>   <int>
#> 1     1
#> 2     2
tibble() %>% relocate(any_of("b"))
#> Error: Can't subset columns that don't exist.
#> x Location 1 doesn't exist.
#> ℹ There are only 0 columns.
tibble() %>% select(any_of("b"))
#> # A tibble: 0 × 0

Created on 2022-01-28 by the reprex package (v2.0.1)

Activity

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

    bugan unexpected problem or unintended behaviorcolumns ↔️Operations on columns: mutate(), select(), rename(), relocate()

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions