ufs (version 0.3.2)

checkPkgs: Check for presence of a package

Description

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.

Usage

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

Run this code
# NOT RUN {
checkPkgs('base');

### This will show the error message
tryCatch(
  checkPkgs(base = "99"),
  error = print
);
# }

Run the code above in your browser using DataLab