From hadley at rice.edu  Tue Nov 16 14:35:09 2010
From: hadley at rice.edu (Hadley Wickham)
Date: Tue, 16 Nov 2010 07:35:09 -0600
Subject: [Rd] Trying to understand the search path and namespaces
In-Reply-To: <20101116155933.41901966@bossiaea>
References: <AANLkTin090pRti8dXknLKtpFmUmmvRsAz6a0V2mx5iOM@mail.gmail.com>
	<AANLkTi=3K0T7qzQnRU-Q8h3RVTDS+UQ5CmcOs4xZJYfD@mail.gmail.com>
	<AANLkTikPE5acZ6CKJeoq9RpphUJffr4W8Lm_8c7O7i08@mail.gmail.com>
	<AANLkTimckaNaUb6SjY=njVZuRSa1iJ+4entWVA2ghBxD@mail.gmail.com>
	<4CE1DE06.9060809@fhcrc.org>
	<AANLkTi=BsP2mE8avreNMBx_P-ORcEhRB_mK0-k8fFTpq@mail.gmail.com>
	<20101116155933.41901966@bossiaea>
Message-ID: <AANLkTi=Hbyf3enveLQiXHr1fu1=cRu8owyMY7GG8R6VV@mail.gmail.com>

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



[Rd] Trying to understand the search path and namespaces
Hadley Wickham