check_package: Check if an object is an installed or attached package

View source: R/check_package.R

check_packageR Documentation

Check if an object is an installed or attached package

Description

Check if a package is installed and if it is installed, check if the version is equal to or higher than the required version or check if a package is attached.

Usage

check_package(x, version = NULL, type = "installed")

assert_package(
  x,
  version = NULL,
  type = "installed",
  .var.name = checkmate::vname(x),
  comment = NULL,
  add = NULL
)

Arguments

x

[any]
Object to check.

version

[character(1)]
The required version of the installed package. May be NULL.

type

[character(1)]
Type of formal check(s) to perform on the package.

installed:

Checks if x is installed.

attached:

Checks if x is attached.

.var.name

[character(1)]
Name of the checked object to print in error messages. Defaults to the heuristic implemented in vname.

comment

[character(1)]
Extra information to be appended to the standard error message in assertions.

add

[AssertCollection]
Collection to store assertions. See AssertCollection.

Value

Depending on the function prefix:
If the check is successful, the function assert_package return x invisibly, whereas check_package return TRUE.
If the check is not successful, assert_package throws an error message and check_package returns a string with the error message.

Examples

# returns TRUE i.e. no error message
check_package(x = "checkmate", version = "2.0.0", type = "installed")

# returns an error message
check_package(x = "nopackage", type = "installed")
check_package(x = "nopackage", type = "attached")

NorwegianVeterinaryInstitute/NVIcheckmate documentation built on Dec. 14, 2024, 10:43 p.m.