These functions check that packages are installed with minimal side effects. If installed, the packages will be loaded but not attached.

  • is_installed() doesn't interact with the user. It simply returns TRUE or FALSE depending on whether the packages are installed.

  • In interactive sessions, check_installed() asks the user whether to install missing packages. If the user accepts, the packages are installed with pak::pkg_install() if available, or utils::install.packages() otherwise. If the session is non interactive or if the user chooses not to install the packages, the current evaluation is aborted.

is_installed(pkg)

check_installed(pkg, reason = NULL)

Arguments

pkg

The package names.

reason

Optional string indicating why is pkg needed. Appears in error messages (if non-interactive) and user prompts (if interactive).

Value

is_installed() returns TRUE if all package names provided in pkg are installed, FALSE otherwise. check_installed() either doesn't return or returns NULL.

Examples

is_installed("utils")
#> [1] TRUE
is_installed(c("base", "ggplot5"))
#> [1] FALSE