Check if a package is available on the local machine and optionally verify a version.
pkg_check(pkgs, versions, stop = FALSE)
a character vector of package names to check for
an optional character vector, of the same length of
pkgs
for the minimum version of the packages.
if TRUE
then an error is thrown if any of the checks fail.
If FALSE
(default) a logical is returned.
When writing a script that will be shared it is very likely that the multiple
authors/users will need to have a certain set of packages available to load.
The pkg_check
function will verify that the packages are available to
load, this includes an optional version test, and attach the package to the
search list if requested.
Testing for package versions will is done as packageVersion(x) >=
version
. If you need a specific version of a package you should explicitly
use packageVersion(x) == version
in your script.