From murdoch at stats.uwo.ca  Mon May  9 07:56:11 2005
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Mon May  9 07:55:39 2005
Subject: [Rd] How to understand packages, namespaces, environments
In-Reply-To: <Pine.LNX.4.61.0505090527030.28603@gannet.stats>
References: <4D99275E380CA94F998977EDACE548DC1AE6B0@extas2-hba.tas.csiro.au>
	<Pine.LNX.4.61.0505090527030.28603@gannet.stats>
Message-ID: <427EFB7B.6090005@stats.uwo.ca>

Prof Brian Ripley wrote:
> On Mon, 9 May 2005 Mark.Bravington@csiro.au wrote:
> 
>> [Alexander Stoddard]
>>
>>> Subject: Re: [Rd] How to understand packages, namespaces, environments
>>>
>>>>
>>>> Does saying the following load package 'foo' into its own
>>>
>>> environment ?
>>>
>>>> > library(foo)
>>>
>>>
>> [Duncan Murdoch]
>>
>>> This loads some of the (name, object) pairs from the package into two
>>> environments:  the public one the user can see, and the
>>> namespace one that the code in the package can see.  They're
>>> related, you don't get two copies of the objects.
>>
>>
>> That's interesting-- I thought there really were two copies. In my debug
>> package, I've taken the approach of changing both copies. Is one of the
>> copies a "master", and the other one something like an activeBinding?
>> Can I get away with changing just one of them?
> 
> 
> Duncan is wrong here (or misquoted).  

Wrong, not misquoted.  Sorry about that.  Thanks for the correct 
description.

Duncan Murdoch

> Loading a package with a namespace 
> loads all the objects in the package (possibly as promises) into the 
> namespace environment.  Then some are copied (using assign) to the 
> package environment.  Since like most R copies this is really 
> copy-on-change you do not get a real copy (nor force a promise) until use.
> 
> See ?fixInNamespace for explicit statements about this.  There can be 
> more than two copies, since importing also `copies', as does S3 method 
> registration (the latter does sometimes force promises).
>


[Rd] How to understand packages, namespaces, environments
Duncan Murdoch