From ripley at stats.ox.ac.uk  Sun Jul 17 15:33:33 2011
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Sun, 17 Jul 2011 14:33:33 +0100 (BST)
Subject: [Rd] NAMESPACE
In-Reply-To: <4E22CE5D.4070404@gmail.com>
References: <CAP01uRnFyMXiEWHCLN=Cp9gdHHRw53hTAjucnb=r0c+kU62GhA@mail.gmail.com>
	<4E22CE5D.4070404@gmail.com>
Message-ID: <alpine.LFD.2.02.1107171429560.31569@gannet.stats.ox.ac.uk>

On Sun, 17 Jul 2011, Duncan Murdoch wrote:

> On 11-07-16 10:13 PM, Gabor Grothendieck wrote:
>>> Packages without explicit ?NAMESPACE? files will have a default one 
>>> created at build or INSTALL time,
>>> so all packages will have namespaces. A consequence of this is that 
>>> ?.First.lib? functions need to be
>>> renamed, usually as ?.onLoad? but sometimes as ?.onAttach?.
>> 
>> Couldn't R simply regard .First.lib as the appropriate function to
>> save many packages from
>> being needlessly changed?
>> 
>
> It is doing that (see today's version of the NEWS), but the problem is that 
> it may choose the wrong one.  If your package requires initialization then 
> yourpkg::somefun only works if the initialization happens in .onLoad.  But 
> some packages only work if the initialization happens when the package is 
> attached.  It's better for the author to make the choice than for R to do it 
> automatically.

True in principle, but so far using .First.lib as a surrogate for
.onAttach seems to work in all cases (whereas using it as surrogate 
for .onLoad did not in ca 20 packages).   Once people start importing 
from packages with automatically produced namespaces, this will likely 
change.

So there is nothing 'needless' about needing to choose the right thing 
for your package.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] NAMESPACE
Prof Brian Ripley