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

conjunct_test_linter: Allow to opt out of linting dplyr::filter() #2108

Closed
salim-b opened this issue Sep 5, 2023 · 2 comments · Fixed by #2110
Closed

conjunct_test_linter: Allow to opt out of linting dplyr::filter() #2108

salim-b opened this issue Sep 5, 2023 · 2 comments · Fixed by #2110
Labels
help wanted ❤️ we'd love your help!

Comments

@salim-b
Copy link
Contributor

salim-b commented Sep 5, 2023

#2077 added support to lint logical conjunctions inside dplyr::filter() calls. Quote:

Relatedly, dplyr::filter(DF, A & B) is the same as dplyr::filter(DF, A, B), but the latter will be more readable / easier to format for long conditions.

I respectfully disagree with the "latter will be more readable" part and would like to use conjunct_test_linter without linting dplyr::filter() calls. Would you be willing to introduce a flag like allow_inside_dplyr_filter to opt out of this behaviour?

@MichaelChirico
Copy link
Collaborator

I think in that sentence the emphasis is on "for long conditions". We often see code like:

DF |>
  filter(
    is_treatment &
      (expenditure - cost > 0) &
      group == "x"
  )

In this case it's not very controversial that using , is better:

DF |>
  filter(
    is_treatment,
    expenditure - cost > 0,
    group == "x"
  )

It's more of a toss-up for simple cases, like A & B vs A, B.

Anyway, happy to accept a PR. I would simply call such an argument allow_filter.

@salim-b
Copy link
Contributor Author

salim-b commented Sep 5, 2023

It's more of a toss-up for simple cases, like A & B vs A, B.

Yeah, but I also think & is clearer than , in differentiating logical conjunctions from logical disjunctions (|).

Anyway, happy to accept a PR. I would simply call such an argument allow_filter.

Cool, see #2110.

MichaelChirico pushed a commit that referenced this issue Sep 6, 2023
* opt out of linting filter() in conjunct_test_linter

fixes #2108

* Use tidyverse style in examples

* Add test for conjunct_test_linter(allow_filter = TRUE)

* Add NEWS bullet

* Merge NEWS items

* Write examples on fewer lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted ❤️ we'd love your help!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants