Skip to contents

Flags 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).

Usage

cl_check_installed_packages(path = ".")

Arguments

path

Path to the package root. Defaults to the current directory.

Value

A tibble following the cranlint check-result contract; see AGENTS.md.

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)