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
.
Arguments
- pkg
Package names. A character vector.
- min_version
Minimum required version number of each
pkg
. Must be eitherNULL
to ignore version numbers, or a vector ofpackage_version
s 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.
See also
Other R package functions:
assert_pkg()
,
is_pkg_cran()
,
is_pkg_dir()
,
is_pkgdown_dir()
,
ls_pkg()
,
use_pkg()
Examples
pal::is_pkg_installed("tidyverse")
#> tidyverse
#> TRUE
# it is vectorized...
pal::is_pkg_installed(pkg = c("dplyr", "tibble", "magrittr"),
min_version = c("1.0", "2.0", "99.9.9000"))
#> dplyr tibble magrittr
#> TRUE TRUE FALSE
# ...and scalar arguments will be recycled
pal::is_pkg_installed(pkg = "dplyr",
min_version = c("0.5", "1.0", "99.9.9000"))
#> dplyr dplyr dplyr
#> TRUE TRUE FALSE
pal::is_pkg_installed(pkg = c("dplyr", "tibble", "magrittr"),
min_version = "1.0")
#> dplyr tibble magrittr
#> TRUE TRUE TRUE