Skip to content

Add grepv() awareness to the package #2856

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Add grepv() awareness to the package #2856

wants to merge 11 commits into from

Conversation

MichaelChirico
Copy link
Collaborator

@MichaelChirico MichaelChirico commented May 7, 2025

Closes #2855. Closes #2648. Progress on #2737

Copy link

codecov bot commented May 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.64%. Comparing base (d590594) to head (a8e7b9f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2856   +/-   ##
=======================================
  Coverage   99.64%   99.64%           
=======================================
  Files         127      127           
  Lines        7068     7070    +2     
=======================================
+ Hits         7043     7045    +2     
  Misses         25       25           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@IndrajeetPatil IndrajeetPatil requested a review from Bisaloo May 18, 2025 12:47
Copy link
Collaborator

@Bisaloo Bisaloo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially in a follow up PR, but if we start recommending grepv() (which I agree with), it would be good to also lint grep(, value = TRUE).

@@ -72,7 +72,7 @@ regex_subset_linter <- function() {
grep_expr,
source_expression = source_expression,
lint_message =
"Prefer grep(pattern, x, ..., value = TRUE) over x[grep(pattern, x, ...)] and x[grepl(pattern, x, ...)].",
"Prefer grepv(pattern, x, ...) over x[grep(pattern, x, ...)] and x[grepl(pattern, x, ...)].",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we maybe customize this error message based on the R version since lintr is still compatible with R 4.0 to 4.4, which don't know about grepv()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't go that way, since the process running {lintr} can be different from the DESCRIPTION dependency, or any other number of incompatibilities between the report and the actual intention.

WDYT about just adding

Use {backports} if your code might also run on R versions before 4.5.0.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good in theory but we would have to wait until r-lib/backports#88 is merged and a new version of backports released.

Maybe the safest option is to be more verbose:

Prefer grepv(pattern, x, ...), or grep(pattern, x, value = TRUE) if your code might also run on R versions before 4.5.0, over x[grep(pattern, x, ...)] and x[grepl(pattern, x, ...)].

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted, PTAL.

@MichaelChirico
Copy link
Collaborator Author

Potentially in a follow up PR, but if we start recommending grepv() (which I agree with), it would be good to also lint grep(, value = TRUE).

Yea, I've been meaning to file that as an issue for a new linter (presumably grepv_linter(), I'm not sure if maybe it should be subsumed in another linter, probably not).

@Bisaloo
Copy link
Collaborator

Bisaloo commented Jun 5, 2025

Also fixes #2648 I think.

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.

lintr is not grepv-aware Reference new grepv() in regex_subset_linter() once it makes an R release
2 participants