Skip to content

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