lintr icon indicating copy to clipboard operation
lintr copied to clipboard

Should we provide a linter to statically detect unsupported currying of base functions?

Open IndrajeetPatil opened this issue 1 year ago • 2 comments

Although R CMD check can detect such usages, it might be a nice feature to detect this statically.

dir <- withr::local_tempdir()
withr::local_options(list(usethis.quiet = TRUE))
library(usethis)
pkg_dir <- create_package(dir, open = FALSE, rstudio = FALSE)

withr::with_dir(pkg_dir, {
  usethis::use_mit_license()
  fs::dir_create("R")
  writeLines(
    c('f <- purrr::partial(gsub, pattern = "/$", replacement = "")', "NULL"), 
    "R/script.R"
  )
  
  rcmdcheck::rcmdcheck(error_on = "warning", quiet = TRUE)
})
#> ── R CMD check results ──────────────────────── file70d53cb58d55 0.0.0.9000 ────
#> Duration: 36.4s
#> 
#> ❯ checking R code for possible problems ... WARNING
#>   Found a .Internal call in the following function:
#>     ‘f’
#>   with calls to .Internal functions
#>     ‘gsub’
#>   
#>   Packages should not call .Internal(): it is not part of the API, for
#>   use only by R itself and subject to change without notice.
#> 
#> 0 errors ✔ | 1 warning ✖ | 0 notes ✔
#> Error: R CMD check found WARNINGs

Created on 2024-04-17 with reprex v2.1.0

That said, I am not sure how to get a list of {base} functions that call .Internal().

IndrajeetPatil avatar Apr 17 '24 17:04 IndrajeetPatil