is_pkg_installed: Test if packages are installed

is_pkg_installedR Documentation

Test if packages are installed

Description

Returns TRUE or FALSE for each pkg, depending on whether the pkg is installed on the current system or not, optionally ensuring a min_version.

Usage

is_pkg_installed(pkg, min_version = NULL)

Arguments

pkg

Package names. A character vector.

min_version

Minimum required version number of each pkg. Must be either NULL to ignore version numbers, or a vector of package_versions or something coercible to.

Details

In contrast to base::require(), this function checks if the packages are installed without attaching their namespaces if so.

In contrast to rlang::is_installed() or xfun::pkg_available(), this function doesn't load the packages if they're installed.

In contrast to xfun::pkg_available(), it is fully vectorized, i.e. returns a (named) logical vector of the same length as pkg.

It is considerably faster than the commonly used pkg %in% rownames(installed.packages()) check.

Value

A named logical vector of the same length as pkg.

See Also

Other R package functions: is_pkg_cran(), is_pkg_dir(), is_pkgdown_dir(), ls_pkg(), use_pkg()

Examples

pal::is_pkg_installed("tidyverse")

# it is vectorized...
pal::is_pkg_installed(pkg = c("dplyr", "tibble", "magrittr"),
                      min_version = c("1.0", "2.0", "99.9.9000"))

# ...and scalar arguments will be recycled
pal::is_pkg_installed(pkg = "dplyr",
                      min_version = c("0.5", "1.0", "99.9.9000"))

pal::is_pkg_installed(pkg = c("dplyr", "tibble", "magrittr"),
                      min_version = "1.0")

salim-b/pal documentation built on Feb. 28, 2025, 6:51 p.m.