From ripley at stats.ox.ac.uk  Thu Sep 21 10:34:07 2006
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Thu, 21 Sep 2006 09:34:07 +0100 (BST)
Subject: [Rd] S4 generics, modify() generic and modifyList() ...
In-Reply-To: <17682.16940.985939.341850@stat.math.ethz.ch>
References: <eb555e660609151222u2f1a7856l6b5f786c8677966@mail.gmail.com>
	<17675.2988.727158.326024@stat.math.ethz.ch>
	<eb555e660609151354t22c68166s4b0144a286c68f50@mail.gmail.com>
	<eb555e660609181500t4f823763t8bdae712333a8e0@mail.gmail.com>
	<971536df0609191311u1dc45bd4w9730b00349826b1@mail.gmail.com>
	<eb555e660609191348u1310c80r414ab2f0cb4b9fa8@mail.gmail.com>
	<17682.16940.985939.341850@stat.math.ethz.ch>
Message-ID: <Pine.LNX.4.64.0609210852320.20269@gannet.stats.ox.ac.uk>

On Thu, 21 Sep 2006, Martin Maechler wrote:

[...]

> For the mid to longer term I agree a modify() generic might be
> nicer, and the method for "function" may even be more useful
> than the one for list  [[and modifyList() would eventually be deprecated]].
>
> OTOH, for new generics, I'd tend to argue we should be nice R-izens
> and use S4 rather than S3.  For the time being that
> would mean it had to go into the methods package.
>
> Or is now {with the dramatic S4 improvements in 2.4.0} a good
> time to start thinking about making "utils" depend on "methods"
> or even "better" [ ;-) I know, not all agree here ]
> think about a dependency tree
>   base -> methods -> [everything else]  for the base packages ?
> so we could merge 'stats4' into 'stats' ?

Please no: that would have a 'dramatic' effect on startup times for the 
'lean and mean' R used as a scripting engine when building R (that often 
uses utils).

Try

gannet% cat > test.R
proc.time()
library(methods)
proc.time()
q()
gannet% env R_DEFAULT_PACKAGES='utils' Rbeta --slave < test.R 
[1] 0.124 0.016 0.125 0.000 0.000
[1] 0.632 0.040 0.657 0.000 0.000

so methods would increase the startup time ca 5x.  There has been no 
discernable progress on the cost of startup of methods when there are no 
S4 generics in the other packages: it is slower than all the other default 
packages put together.  Similarly, there is a considerable cost to S3 
dispatch of having an S4 take-over of S3 generics (especially internal 
generics).

Good 'R-izens' need to consider the environmental impact of their use of 
S4 code.  One thing we may be getting closer to is not making 'methods' a 
default package at all, but loading it only when needed.  (Now S4 objects 
can be identified easliy, that could be checked when one is 
created/loaded.) It is like the on-going debate on 4x4 vehicles (SUVs to 
Americans), which carry a lot of extra weight for off-road features that 
are almost never used.

-- 
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] S4 generics, modify() generic and modifyList() ...
Prof Brian Ripley