Checks if a character vector of R packages are installed, installs them if they are not currently installed, and loads them in the namespace.

util_load_pkg(
  pkg,
  github = NULL,
  lib.loc = .libPaths()[1],
  repos = "https://cran.rstudio.org",
  dependencies = TRUE,
  type = "source",
  update = FALSE
)

Arguments

pkg

Character vector. Packages to install.

github

Character vector. Packages from Github to install.

lib.loc

character vector describing the location of R library trees to search through (and update packages therein), or NULL for all known trees (see .libPaths).

repos

character vector, the base URL(s) of the repositories to use, e.g., the URL of a CRAN mirror such as "https://cloud.r-project.org".

dependencies

logical indicating whether to also install uninstalled packages which these packages depend on/link to/import/suggest (and so on recursively). Not used if repos = NULL. Can also be a character vector, a subset of c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances").

Only supported if lib is of length one (or missing), so it is unambiguous where to install the dependent packages. If this is not the case it is ignored, with a warning.

The default, NA, means c("Depends", "Imports", "LinkingTo").

TRUE means to use c("Depends", "Imports", "LinkingTo", "Suggests") for pkgs and c("Depends", "Imports", "LinkingTo") for added dependencies: this installs all the packages needed to run pkgs, their examples, tests and vignettes (if the package author specified them correctly).

In all of these, "LinkingTo" is omitted for binary packages.

type

character, indicating the type of package to download and install. See install.packages.

update

Logical. Update installed packages.

Author

Ivan Jacob Agaloos Pesigan

Examples

pkg <- c( "parallel", "stats", "stats4" ) util_load_pkg( pkg = pkg )