R/install.on.demand.R

Defines functions install.on.demand

install.on.demand <- function(pkg, quiet = FALSE, ...) {
  # internal function that checks whether package pkg is
  # in the library. If not found, it asks the user permission
  # to install from CRAN.
  if (requireNamespace(pkg, quietly = TRUE)) {
    return()
  }
  if (interactive()) {
    answer <- askYesNo(paste("Package", pkg, "needed. Install from CRAN?"))
    if (answer) install.packages(pkg, repos = "https://cloud.r-project.org/", quiet = quiet)
  }
}
stefvanbuuren/mice documentation built on April 21, 2024, 7:37 a.m.