Learn R Programming

suggests (version 0.1.0)

is_installed: Check whether packages are installed

Description

Initially, utils::packageVersion() is used to try to retrieve a version from a package's DESCRIPTION file. This is a fast method, but doesn't categorically guarantee that the package is actually available to use.

If load = TRUE, then base::requireNamespace() is used to try to load the namespace of each package in turn. This is much slower, but is the closest we can get to ensuring that the package is genuinely usable.

Usage

is_installed(pkgs, load = FALSE, lib.loc = NULL)

Value

A logical vector of the same length as pkgs, where each element is TRUE if the package is installed, and FALSE otherwise.

Arguments

pkgs

A character vector of package names. You can check for a minimum version by appending >=[version] to a package name - see Examples.

load

Whether to make sure packages can be loaded - significantly slower, but gives an extra level of certainty.

lib.loc

Passed to utils::packageVersion().

Examples

Run this code
  is_installed("base")
  is_installed(c("base", "utils"))

  is_installed("base>=3.0.0")
  is_installed(c(
    "base>=3.0.0",
    "utils"
  ))

Run the code above in your browser using DataLab