R/package-namespace-helpers.R

loaded_user_pkgs <- function() {
  loaded <- loadedNamespaces()
  ip <- installed.packages()
  basePkgs <- rownames(ip)[!is.na(ip[, "Priority"])]
  loaded[!(loaded %in% basePkgs)]
}

ns_imports <- function(packages) {
  setNames(lapply(packages, ns_imports_single), packages)
}

ns_imports_single <- function(package) {
  ns <- asNamespace(package)
  names(getNamespaceImports(ns))
}

is_imported <- function(package) {
  imports <- ns_imports(loadedNamespaces())
  any(sapply(imports, function(x) package %in% x))
}

unloadable <- function(packages) {
  result <- sapply(packages, Negate(is_imported))
  names(result)[result]
}

Try the packrat package in your browser

Any scripts or data that you put into this service are public.

packrat documentation built on May 2, 2019, 6:24 a.m.