R/attach.R

Defines functions tidyverse_attach same_library core_unloaded

core <- c("dplyr", "tidyr", "ttservice", "ggplot2")

core_unloaded <- function() {
    search <- paste0("package:", core)
    core[!search %in% search()]
}

# Attach the package from the same library it was loaded from before.
# [source: https://github.com/tidy-biology/tidyverse/issues/171]
same_library <- function(pkg) {
    loc <- if (pkg %in% loadedNamespaces()) 
        dirname(getNamespaceInfo(pkg, "path"))
    library(pkg, lib.loc=loc, character.only=TRUE, warn.conflicts=FALSE)
}

tidyverse_attach <- function() {
    to_load <- core_unloaded()
    
    suppressPackageStartupMessages(
        lapply(to_load, same_library))
    
    invisible(to_load)
}
stemangiola/tidySCE documentation built on May 13, 2024, 3:16 a.m.