Skip to contents

[Deprecated]
This function has been deprecated in favor of the more powerful rlang::check_installed() and will be removed in the future.

Asserts a package is installed on the current system, optionally ensuring a min_version. If the package is not installed, an informative error message is thrown that by default includes an autogenerated install_hint.

Usage

assert_pkg(pkg, min_version = NULL, message = NULL, install_hint = NULL)

Arguments

pkg

Package name (case-sensitive). A character scalar.

min_version

Minimum required version number of pkg. Must be either NULL to ignore version numbers, or a single package_version or something coercible to.

message

Error message to display in case the package is not installed. Supports cli's inline markup. If NULL, a sensible standard message is generated.

install_hint

Additional package installation instructions appended to message. Either NULL in order to autogenerate the hint, or a character scalar. Set install_hint = "" in order to disable the hint.

Value

pkg, invisibly.

See also

rlang::check_installed()

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

Other functions extending the checkmate package: assert_class_any(), assert_cli(), assert_df_or_tibble(), assert_inf_count(), assert_mime_type()

Examples

pal::assert_pkg("pal")

pal::assert_pkg(pkg = "glue",
                message = paste("You should really consider to install the awesome {.pkg {pkg}}",
                                "package! It's the glue that keeps strings and variables",
                                "together 🤲."))
try(
  pal::assert_pkg("pal", min_version = "9999.9")
)
#> Error in pal::assert_pkg("pal", min_version = "9999.9") : 
#>   Package pal (>= 9999.9) is required for this operation but installed version is 0.0.9101. Please first update pal and then try again. Note that pal is
#> not available on CRAN.

try(
  pal::assert_pkg("yay",
                  install_hint = paste0("To install the latest development version, run ",
                                        "{.code remotes::install_gitlab(\"rpkg.dev/yay\")}."))
)