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)
)

@DavisVaughan
Copy link
Member

The current behavior is currently purposeful, see #4612

But we are going to reevaluate whether we need it at all anymore. Either way, this current PR won't be the final solution we land on, but thank you for your efforts here!

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

2 participants