From ripley at stats.ox.ac.uk  Sun Oct 17 19:10:35 2004
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Sun Oct 17 19:10:54 2004
Subject: [Rd] Lazy loading - importance of NAMESPACE
In-Reply-To: <200410171633.i9HGXnaF003532@outmx015.isp.belgacom.be>
Message-ID: <Pine.LNX.4.44.0410171752250.17145-100000@gannet.stats>

I think you are leaping to a conclusion from a single example.  Lots of 
things have changed in 2.0.0 and you are repeatedly attributing symptoms 
to lazy loading without any real evidence.

I have tested several hundred examples with and without lazy loading, and
I have seen no dramatic changes caused by lazy loading.  I have seen
dramatic changes caused by the way the DESCRIPTION file is interpreted,
and I did stress the importance of getting that right.

On Sun, 17 Oct 2004, Philippe Grosjean wrote:

> Hello all,
> 
> Following a question in r-help, where I was wondering why my large package
> with lots of "Depends:" did load so slowly (almost 30 sec in lazy loading in
> R 2.0.0 under Win XP, for 3.4 sec in R 1.9.1 on the same machine), I
> discovered that a correct namespace changes everything: with the namespace
> added, loading of my package drops to circa 1 sec, which is more that three
> times faster than in R 1.9.1 without lazy loading,... and about 30 times
> faster than without the namespace in R 2.0.0!

You are not comparing like with like, AFAICS.  In 1.9.1 you were not 
loading all the dependent packages. In 2.0.0 you were.  If you add a 
NAMESPACE, nothing changed.  If you replace Depends: by Imports: you don't 
need to initialize all the dependent packages, and that may well save you 
a lot of time (for example there is no search for and cacheing of S4 
methods).

But none of this has anything whatsoever to do with lazy loading!

> First of all, congratulation for implementing lazy loading!
> 
> Second, I look in the documentation, and in the Brian Ripley's article in R
> News 2/2004, and I found nowhere a place where the importance of namespace
> is stressed for lazy loading (although Brian Ripley explains in several
> places differences in lazy loading with and without namespace). I think it
> is something important and, unless I miss it in the documentation, it would
> be useful to tell somewhere that a namespace is strongly recommended in
> conjonction with lazy loading...
> 
> Finally, a question:
> >From R News 2/2004 p. 30: "a 'Imports:' field for packages whose namespaces
> are used but do not need to be attached." OK, functions in these namespaces
> are available to me, without attaching the package.

They are not.  They are available to functions in your package's 
namespace.

> Now, if I need to attach
> these packages at a later time because I will use some of their functions
> from the command line, then, is this package referred twice (once in my
> package environment, once attached to the search path)? If yes, what is the
> drawback in term of ressources and speed ('Imports' versus 'Depends', both
> in loading, and in use of such a package)?

That makes no sense to me.  A package should be named in either Imports 
or Depends and not both.  For you to access it, you need to call 
library().  That does not load another copy of the namespace, and the 
total amount of work is essentially the same as if you called library() on 
it before your own package (which is what Depends; will do).  Does that 
answer the question you mean to ask?

-- 
Brian D. Ripley,                  ripley@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] Lazy loading - importance of NAMESPACE
Prof Brian Ripley