This function efficiently checks for the presence of a package without installing it (unlike library() or require(). This is useful to force yourself to use the package::function syntax for addressing functions; you can make sure required packages are installed, but their namespace won't attach to the search path.

checkPkgs(
  ...,
  install = FALSE,
  load = FALSE,
  repos = "https://cran.rstudio.com"
)

Arguments

...

A vector with packages. If this is a names vector, the names are the package names, and the values are the minimum required package versions.

install

Whether to install missing packages from repos.

load

Whether to load packages (which is exactly not the point of this package, but hey, YMMV).

repos

The repository to use if installing packages; default is the RStudio repository.

Value

Invisibly, a vector of the available packages.

Examples

checkPkgs('base'); ### This will show the error message tryCatch( checkPkgs(base = "99"), error = print );
#> <simpleError in checkPkgs(base = "99"): Of package(s) 'base', you need at least versions 99, respectively. Install those with: #> #> install.packages(c('base')); #> >