R/detach_pkg.R

#' Detach Packages from Workspace
#'
#' This function allows for packages loaded into the workspace previously to be dettached, thus reducing the risk of functions being masked.
#' @param pkg The package name
#' @export
detach_package <- function(pkg, character.only = FALSE)
{
  if(!character.only)
  {
    pkg <- deparse(substitute(pkg))
  }
  search_item <- paste("package", pkg, sep = ":")
  while(search_item %in% search())
  {
    detach(search_item, unload = TRUE, character.only = TRUE)
  }
}
thomaspinder/usefulRFunctions documentation built on May 10, 2019, 8:27 a.m.