dependencies: Simplified loading and installing of packages

View source: R/misc_functions.R

dependenciesR Documentation

Simplified loading and installing of packages

Description

This is a wrapper to require and install.packages. Specifically, this will first try to load the package(s) and if not found it will install then load and attach the packages. Additionally, if the update=TRUE parameter is specified it will check the currently installed package version with what is available on CRAN (or mirror) and install the newer version.

Usage

dependencies(
  pkges,
  install = TRUE,
  update = FALSE,
  quiet = TRUE,
  verbose = FALSE,
  ...
)

Arguments

pkges

a character vector with the names of the packages to load.

install

if TRUE (default), any packages not already installed will be.

update

if TRUE, this function will install a newer version of the package if available.

quiet

if TRUE (default), package startup messages will be suppressed.

verbose

if TRUE (default), diagnostic messages will be printed.

...

other parameters passed to require, install.packages, and available.packages.

Details

The function was originally created by Jason Bryer here and the source is available here. Note: I renamed the function to dependencies and adapted it to attach instead of only load the packages.

Value

a data frame with four columns and rownames corresponding to the packages to be loaded. The four columns are: loaded (logical indicating whether the package was successfully loaded), installed (logical indicating that the package was installed or updated), loaded.version (the version string of the installed package), and available.version (the version string of the package currently available on CRAN). Note that this only reflects packages listed in the pkges parameter. Other packages may be loaded and/or installed as necessary by install.packages and require. If verbose=FALSE the data frame will be returned using invisible.

Examples

## Not run: 
dependencies(c('devtools','lattice','ggplot2','psych'))

## End(Not run)

ChristK/CKutils documentation built on April 11, 2025, 10:11 p.m.