Skip to contents

Function-body helper for morie endpoints that require optional Suggests: packages. If every package in pkgs is already installed, returns silently. Otherwise:

Usage

morie_ensure_extras(pkgs, ask = interactive(), repos = NULL)

Arguments

pkgs

Character vector of required package names.

ask

Logical. If TRUE (default), prompt in interactive sessions. Pass FALSE to skip the prompt and behave like non-interactive: error out with the install-hint message.

repos

Optional CRAN repo URL(s). Default uses getOption("repos"), falling back to RStudio CRAN.

Value

Invisibly TRUE if all pkgs are (now) installed; throws otherwise.

Details

  • In an interactive session, prompts the user once, and on consent installs the missing packages via utils::install.packages().

  • In a non-interactive session (R CMD check, CI, Rscript), throws an informative error with the morie command the user should run to fix things: morie_install_extras(c("X", "Y")).

Why not auto-install silently? CRAN policy forbids packages from writing to the user's library or making network calls at function call time without explicit consent. The interactive prompt is the CRAN-blessed escape: the user IS the one consenting, and during R CMD check or any non-interactive run, the function refuses to touch the library.

Typical use inside a morie function body that needs DoubleML and ranger:


morie_estimate_irm <- function(...) {
  morie_ensure_extras(c("DoubleML", "ranger"))
  ...
}

See also

morie_install_extras() for the user-facing bulk installer.

Examples

if (FALSE) { # \dontrun{
  # Interactive (RStudio / R console): prompts to install if needed
  morie_ensure_extras(c("DoubleML", "ranger"))

  # CI / Rscript: errors with install-hint instead of installing
  morie_ensure_extras(c("DoubleML"), ask = FALSE)
} # }