Skip to content

option to disable the object_usage_linter inside with expressions #1458

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

Closed
AdrienLeGuillou opened this issue Jul 18, 2022 · 3 comments · Fixed by #1548
Closed

option to disable the object_usage_linter inside with expressions #1458

AdrienLeGuillou opened this issue Jul 18, 2022 · 3 comments · Fixed by #1548
Labels
false-positive code that shouldn't lint, but does

Comments

@AdrienLeGuillou
Copy link

would it be possible to add an option to the object_usage_linter so it does not check the inside of with expressions?

running lintr::lint("this_file.R")

#this_file.R
test_fun <- function(df) {
  with(df, first_var + second_var)
}

throw the following warnings:

this_file.R:2:12: warning: [object_usag e_linter] no visible binding for global variable ‘first_var’ with(df, first_var + second_var)
this_file.R:2:24: warning: [object_usag e_linter] no visible binding for global variable ‘second_var’ with(df, first_var + second_var)

but strangely no such warning appear with this code:

df <- readRDS("df_path.rds")
with(df, first_var + second_var)

Thanks

@AshesITR
Copy link
Collaborator

Hi, thanks for reporting this.
codetools::checkUsage() reports these issues by default, but it has a flag skipWith = FALSE that could be set to true to suppress these.

Regarding your second example: The object usage linter only checks (top-level) function definitions, so the second example doesn't trigger it.

@AshesITR
Copy link
Collaborator

Related: #941

@AdrienLeGuillou
Copy link
Author

Thanks for your answer, I will follow this issue then!

IndrajeetPatil added a commit that referenced this issue Sep 25, 2022
* Add arg to skip `with()` in `object_usage_linter()`

Closes #1458

* Skip `with()` expressions by default

Closes #941

* address review comments

* Update NEWS.md

* Use character vector instead

Co-authored-by: Michael Chirico <chiricom@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive code that shouldn't lint, but does
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants