Check for calls to installed.packages()
Source:R/check-installed-packages.R
cl_check_installed_packages.RdFlags any call to installed.packages() in R/. Per the CRAN Cookbook,
this function can be slow (it reads several files per installed
package) and shouldn't be used to test whether a package is available;
requireNamespace()/require() are the recommended replacements (or
find.package()/system.file() to locate one, packageDescription()
for details of a small number of packages).
Examples
pkg_dir <- cl_example_pkg(
r_files = list(foo.R = c(
"has_pkg <- function(pkg) {",
" pkg %in% rownames(installed.packages())",
"}"
))
)
cl_check_installed_packages(pkg_dir)
#> # A tibble: 1 × 6
#> check file line severity message policy_reference
#> <chr> <chr> <int> <ord> <chr> <chr>
#> 1 installed_packages R/foo.R 2 should_fix installed.packag… https://contrib…
unlink(pkg_dir, recursive = TRUE)