-
Notifications
You must be signed in to change notification settings - Fork 186
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
Consider ways to work around stats::filter() when applying dplyr::filter() lints #2078
Comments
Some tests I'd written about this future behavior: # TODO(michaelchirico): shut these off to stay on the conservative side and
# only lint for calls that we _know_ are coming from dplyr. consider
# whether to use an argument to change this, or if we can improve the
# logic to ensure dplyr::filter() is being used.
# using & in stats::filter() calls should be uncommon, but ensure
# either dplyr:: is used or there's no namespace qualification
expect_lint(
"stats::filter(A & B)",
NULL,
conjunct_test_linter()
)
expect_lint(
"ns::filter(A & B)",
NULL,
conjunct_test_linter()
)
expect_lint(
"DF %>% filter(A & B)",
"Use dplyr::filter\\(DF, A, B\\) instead of dplyr::filter\\(DF, A & B\\)",
conjunct_test_linter()
) |
Or instead we do a dynamic check if the globally loaded / NAMESPACE-Imported I think both approaches would greatly increase the amount of true positives. Also good call we should never lint package-prefixed calls from other packages than dplyr. |
I've also seen |
I've also seen this... maybe more appropriate for vector_logic_linter()? |
Now that we have WDYT about |
The options, especially Maybe |
|
But we dont "allow_filter" "qualified_dplyr" 😅 We allow everything but qualified dplyr calls. |
Another idea: |
Just my 5 cents: If it's possible for lintr to auto-detect this, i.e. to
I'd strongly prefer that instead of extending parameters. 🙂 |
We might do that in addition to extending parameters, but requiring that is not appealing to me in general -- it requires the machine executing the linter to have dplyr installed, which may be true for developers working locally on their own package, but is not true by default in distributed work environments. Another suggestion:
Otherwise, |
Follow-up to #2077.
That PR is conservative about what
filter()
calls to include. We do not matchfilter()
unless it's namespace-qualified, to avoid false positives involvingstats::filter()
. I'm not so familiar withstats::filter()
, but my understanding is it'd be really weird to use&
there too, but in any case the lint message would look strange.We might parameterize this instead to increase the reach, e.g.
assume_dplyr
, whenTRUE
allfilter()
calls are matched, orallow_conjunct_filter
, whenTRUE
allfilter()
calls are skipped.Another less conservative option: assume
filter()
isdplyr::filter()
, unless it's namespace-qualified as coming from another namespace. That gives users an out if needed, but defaults to assuming everything comes fromdplyr
(which seems most likely, among users who'd have this lint active)The text was updated successfully, but these errors were encountered: