R/ipak.R

Defines functions ipak

Documented in ipak

# Load vector of packages, install if needed
#' ipak Function
#'
#' This function loads the packages and install them from CRAN or Bioconductor if needed
#'
#' @param pkg a vector of characters naming packages
#' @details Function inspired by Kelly Street
#' @export
#' @examples
#' DailyHRB::ipak(c("ggplot2", "Biobase"))
ipak <- function(pkg){
  new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
  if (length(new.pkg)) {
    if (!"BiocManager" %in% installed.packages()) {
      install.packages("BiocManager")
    }
    BiocManager::install(new.pkg, dependencies = TRUE)
  }
  sapply(pkg, require, character.only = TRUE)
}
HectorRDB/HectorRDB documentation built on Oct. 15, 2020, 6:16 p.m.