require_namespaces {mlr3misc} | R Documentation

## Require Multiple Namespaces

### Description

Packages are loaded (not attached) via `base::requireNamespace()`. If at least on package can not be loaded, an exception of class "packageNotFoundError" is raised. The character vector of missing packages is stored in the condition as `packages`.

### Usage

    require_namespaces(
      pkgs,
      msg = "The following packages could not be loaded: %s",
      quietly = FALSE
    )

### Arguments

`pkgs` | (`character()`) Packages to load.
`msg` | (`character(1)`) Message to print on error. Use `"%s"` as placeholder for the list of packages.
`quietly` | (`logical(1)`) If `TRUE` then returns `TRUE` if all packages available, otherwise `FALSE`.

### Value

(named `character()`) of loaded packages (invisibly).

### Examples

    require_namespaces("mlr3misc")

    # catch condition, return missing packages
    tryCatch(require_namespaces(c("mlr3misc", "foobaaar")),
      packageNotFoundError = function(e) e$packages)

[Package mlr3misc version 0.8.0 Index]