lintr icon indicating copy to clipboard operation
lintr copied to clipboard

option to disable the `object_usage_linter` inside `with` expressions

Open AdrienLeGuillou opened this issue 3 years ago • 3 comments

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

AdrienLeGuillou avatar Jul 18 '22 09:07 AdrienLeGuillou

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 avatar Jul 18 '22 10:07 AshesITR

Related: #941

AshesITR avatar Jul 18 '22 10:07 AshesITR

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

AdrienLeGuillou avatar Jul 18 '22 11:07 AdrienLeGuillou