Learn R Programming

assertions (version 0.3.0)

assert_packages_installed: Assert packages are installed

Description

Assert that one or more packages are installed.

Usage

assert_packages_installed(
  x,
  msg = NULL,
  call = rlang::caller_env(),
  arg_name = NULL
)

Value

invisible(TRUE) if x is installed, otherwise aborts with the message specified by msg

Arguments

x

Package name(s) (character vector)

msg

A character string containing the error message to display if the package is not installed

call

Only relevant when pooling assertions into multi-assertion helper functions. See cli_abort for details.

arg_name

Advanced use only. Name of the argument passed (default: NULL, will automatically extract arg_name).

Examples

Run this code
try({
assert_packages_installed("stats") # Passes
assert_packages_installed(c("stats", "utils")) # Passes
assert_packages_installed("notapackage123") # Throws Error
})

Run the code above in your browser using DataLab