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

Add logic to catch single named logical expressions #7113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

brendensm
Copy link

This PR would close #7105. This is a potential solution that adds logic to check_filter. This solution stops single, named logical expressions.

mtcars$big_cyl <- mtcars$cyl > 4

filter(mtcars, big_cyl = TRUE) |>
  nrow()
#> Error in `filter()`:
#> ! We detected a named input.
#> ℹ This usually means that you've used `=` instead of `==`.
#> ℹ Did you mean `big_cyl == TRUE`?
#> 
filter(mtcars, big_cyl == TRUE) |>
  nrow()
#> [1] 21
#>

But still allows for named logical vectors:

filters <- mtcars %>%
  transmute(
    cyl %in% 6:8,
    hp / drat > 50
  )

expect_identical(
  mtcars %>% filter(!!!unname(filters)),
  mtcars %>% filter(!!!filters)
)

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 this pull request may close these issues.

filter should warn or prevent users from using named logical inputs
1 participant