[Rd] Trying to understand the search path and namespaces

Hadley Wickham hadley at rice.edu
Tue Nov 16 14:35:09 CET 2010


>> 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.

Well, if we're going to pick nits, I meant that the parents of the
environment are dynamic.

>> > 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.

It's still not at all obvious how this happens - when does variable
look up use the stack of environments given by the package environment
and when does it use the stack of environments given by the namespace?

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-devel mailing list