R/zzz.R

Defines functions .onLoad .onAttach hasData

.pkgenv <- new.env(parent=emptyenv())

.onLoad  <- function(libname, pkgname) {
  has_data <- requireNamespace("cfsalesdata1", quietly = TRUE)
  .pkgenv[["has_data"]] <- has_data
}

.onAttach <- function(libname, pkgname) {
  if (!.pkgenv$has_data) {
    msg <- paste("To use this package, you must install the",
                 "cfsalesdata package. To install that ",
                 "package, run `install.packages('cfsalesdata1',",
                 "repos='https://alexhallam.github.io/drat/', type='source')`.")
    msg <- paste(strwrap(msg), collapse="\n")
    packageStartupMessage(msg)
  }
}

hasData <- function(has_data = .pkgenv$has_data) {
  if (!has_data) {
    msg <- paste("To use this function, you must have the",
                 "`cfsalesdata` package installed. See the")
    msg <- paste(strwrap(msg), collapse="\n")
    stop(msg)
  }
}
alexhallam/cfsales documentation built on Oct. 1, 2019, 2:50 a.m.