R/zzz.R

Defines functions .onAttach is_attached

# This script is from the tidyverse package
load <- c("dplyr", "readr", "lme4", "agridat")

# Function to run when the package is attached
.onAttach <- function(...) {

  # Find the packages that aren't already attached
  needed <- load[!is_attached(load)]

  if (length(needed) == 0)
    return()

  packageStartupMessage(paste0("Loading pbr: ", needed, collapse = "\n"))
  suppressPackageStartupMessages(
    lapply(needed, library, character.only = TRUE, warn.conflicts = FALSE)
  )

}

is_attached <- function(x) {
  paste0("package:", x) %in% search()
}
neyhartj/pbr documentation built on Jan. 7, 2020, 9:24 a.m.