Wednesday, June 29, 2011

Using detach() to unload a library

Just a quick tidbit about unloading a library from the current R session using detach().

Say we have a current session of R open, and, lo and behold, there is a new version of "phytools" available. If we download the binaries and try to install, e.g.:

> install.packages("",repos=NULL)

we get the following error:

Warning: package 'phytools' is in use and will not be installed

This can be avoided simply by unloading the library before installing, and the reloading the new version afterwards. This is accomplished as follows:

> detach(package:phytools)
> install.packages("",repos=NULL)
package 'phytools' successfully unpacked and MD5 sums checked
> require(phytools)
Loading required package: phytools

Of course, this also applies to packages installed from a CRAN mirror.


  1. This a very old post, but I think this will not really unload the package unless you do:


  2. Hi Liam
    Very helpful post. I am trying to cut my tree as well.
    Here is the structure of my tree:
    List of 4
    $ edge : int [1:508, 1:2] 256 509 323 322 321 320 319 318 317 309 ...
    $ edge.length: num [1:508] 0 0 0 0 0 ...
    $ tip.label : chr [1:255] "hxAUG26up1s7g100t1" "hxAUG26us32g70t1" "hxAUG26rep1s3g123t1" "hxNCBI_GNO_60424" ...
    $ Nnode : int 254
    - attr(*, "class")= chr "phylo"
    - attr(*, "order")= chr "cladewise"

    When I use your program as follows:
    Error in if (node <= Ntip) stop("node number must be greater than the number of tips") :
    missing value where TRUE/FALSE needed
    I receive the above error.
    Any help is appreciated.

  3. This comment has been removed by the author.

  4. Truly, there might be a few special cases since libraries, large as they frequently seem to be, do have constrained rack space, so they have to ensure the books they convey will be perused by their story online

  5. Composing your content will be a noteworthy undertaking in that it requests an alternate style of thinking of, one that is denser and progressively compacted. fakuu