How to unload a package without restarting R?


You can also use the unloadNamespace command, as in:


The function detaches the namespace prior to unloading it.


I'd like to unload a package without having to restart R (mostly because restarting R as I try out different, conflicting packages is getting frustrating, but conceivably this could be used in a program to use one function and then another--although namespace referencing is probably a better idea for that use).

?library doesn't show any options that would unload a package.

There is a suggestion that detach can unload package, but the following both fail:


Error in detach(vegan) : invalid name argument


Error in detach("vegan") : invalid name argument

So how do I unload a package?

I tried what kohske wrote as an answer and I got error again, so I did some search and found this which worked for me (R 3.0.2):

require(splines) # package

or also

pkg <- "package:splines"
detach(pkg, character.only = TRUE)

Just go to OUTPUT window, then click on Packages icon (it is located between Plot and Help icons). Remove "tick / check mark" from the package you wanted be unload.

For again using the package just put a "tick or Check mark" in front of package or use :

library (lme4)