Unload your R packages

Very few times, we want to unload either some of the selected packages or all of the packages. Although there is a simple way around it,  i.e., to restart the R session, but this gives a lot of pain by re-running each functions on reload. While dealing with the same situation, I found a simple three line code  from Stack Overflow link. Here is the code

pkgs = names(sessionInfo()$otherPkgs) # finds all the loaded pkgs
pkgs_namspace = paste('package:',pkgs,sep = "")
# please find ?detach for meanings of option used
lapply(pkgs_namespace,detach, character.only=TRUE,unload=TRUE,force=TRUE)

To remove a specific package say xyz, we use

detach("package:xyz") # please use ?detach for options



Please excuse, if any typos found



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s