[Rd] Trying to understand the search path and namespaces

Berwin A Turlach berwin at maths.uwa.edu.au
Tue Nov 16 08:59:33 CET 2010

G'day Hadley,

On Mon, 15 Nov 2010 19:45:30 -0600
Hadley Wickham <hadley at rice.edu> wrote:

> > 1.6 of Writing R Extensions says
> >
> > Note that adding a name space to a package changes the search
> > strategy. The package name space comes first in the search, then
> > the imports, then the base name space and then the normal search
> > path.
> >
> > I'm not sure of the details, but I think
> >
> >  parents(getNamespace("devtools"))
> Ah, my mistake was assuming that the package namespace and environment
> were the same thing.
> Interestingly the namespace is dynamic:

Not sure what you mean with this.  Section 1.6 of "Writing R
Extensions" explicitly states:

	Name spaces are @emph{sealed} once they are loaded.  Sealing
	means that imports and exports cannot be changed and that
	internal variable bindings cannot be changed.

> > parents(getNamespace("devtools"))
> ...
> [31] "base"
> > library(roxygen)
> > parents(getNamespace("devtools"))
> ...
> [31] "Autoloads"            "base"

Well, as the part of "Writing R Extensions" that Martin quoted states,
the normal search path is part of the search path used by packages with
name spaces.  So if you attach another package via library(), the
normal search path changes and, hence,
`parents(getNamespace("devtools"))' has one more location to report.



More information about the R-devel mailing list