Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Packages and Namespaces

Detaching a package does not unload its namespace from R. Unloading a namespace does not de-register its methods. As Gabor Grothendieck points out on r-help on 26 Mar 2007:



> search()
[1] ".GlobalEnv"        "package:stats"     "package:graphics"
[4] "package:grDevices" "package:utils"     "package:datasets"
[7] "package:methods"   "Autoloads"         "package:base"
> loadedNamespaces()
[1] "base"      "graphics"  "grDevices" "methods"   "stats"     "utils"
> as.Date(1) # error as there is no numeric method for as.Date
Error in as.Date.default(1) : do not know how to convert '1' to class "Date"

> library(zoo)
> search()
 [1] ".GlobalEnv"        "package:zoo"       "package:stats"
 [4] "package:graphics"  "package:grDevices" "package:utils"
 [7] "package:datasets"  "package:methods"   "Autoloads"
[10] "package:base"
> loadedNamespaces()
[1] "base"      "graphics"  "grDevices" "grid"      "lattice"   "methods"
[7] "stats"     "utils"     "zoo"
> as.Date(1) # zoo defines a numeric method for as.Date
[1] "1970-01-02"

> detach()
> unloadNamespace("zoo")
<environment: namespace:zoo>
> search()
[1] ".GlobalEnv"        "package:stats"     "package:graphics"
[4] "package:grDevices" "package:utils"     "package:datasets"
[7] "package:methods"   "Autoloads"         "package:base"
> loadedNamespaces()
[1] "base"      "graphics"  "grDevices" "grid"      "lattice"   "methods"
[7] "stats"     "utils"
> # zoo is gone from attached package list and loadedNamespaces
> # but numeric method for as.Date from zoo is still registered
> as.Date(1)
[1] "1970-01-02"



Copyright © Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010