Skip to content

Option to eval_select() to disallow empty selections #252

@DavisVaughan

Description

@DavisVaughan

i.e.

library(tidyselect)
library(rlang)

df <- data.frame(x = 1)

# In some cases, I'd like this to be an error
eval_select(expr(starts_with("foo")), df)
#> named integer(0)

In tidyr, we have 3 places where we check that the result of eval_select() selects "at least 1 column", like
https://github.com/tidyverse/tidyr/pull/1241/files#diff-082bcbb672e069ebb562fb3b877b4d9457f867d89ba382224e1041ce90a89ff4R308

I like that this is already an error by default:

library(tidyselect)
library(rlang)

df <- data.frame(x = 1)

eval_select(expr(y), df)
#> Error: Can't subset columns that don't exist.
#> x Column `y` doesn't exist.

but I think it might make sense to have an ultra strict mode as well that can't ever result in an empty selection

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions