R/package-namespace-helpers.R

Defines functions unloadable is_imported ns_imports_single ns_imports loaded_user_pkgs

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 Sept. 8, 2023, 5:44 p.m.