How to unload a package without restarting R

How to unload a package without restarting R

Try this (see ?detach for more details):

detach(package:vegan, unload=TRUE)

It is possible to have multiple versions of a package loaded at once (for example, if you have a development version and a stable version in different libraries). To guarantee that all copies are detached, use this function.

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)
  }
}

Usage is, for example

detach_package(vegan)

or

detach_package(vegan, TRUE)

You can also use the unloadNamespace command, as in:

unloadNamespace(sqldf)

The function detaches the namespace prior to unloading it.

How to unload a package without restarting R

You can uncheck the checkbox button in RStudio (packages).

RStudio

Leave a Reply

Your email address will not be published.