[Rd] LazyLoad changes the class of objects

Gabor Grothendieck ggrothendieck at gmail.com
Wed Oct 17 17:07:14 CEST 2007

On 10/17/07, Henrik Bengtsson <hb at stat.berkeley.edu> wrote:
> Yes (on the yes), to second Luke.  Here is John Chambers' comment when
> I was bitten by the same "bug" a while ago:
>  http://tolstoy.newcastle.edu.au/R/devel/02b/0524.html
> See also Peter Dalgaard's follow up suggesting to wrap up the
> environment in a list, which will typically be enough.  I've been
> using this "trick" successfully in the Object class (R.oo package) for
> several years, where I'm putting the environment in the attributes
> list of an object, i.e.  obj <- NA; attr(NA, "..env") <- new.env();
> It turned out at the time that this was slightly faster to access than
> using a list element.

This has all been discussed before but this "trick" is not sufficient
for defining an environment subclass because it does not respect
inheritance.  The subclass writer must replicate all methods that
act on environments in a subclass for an environment subclass to
have them.  Inheritance is completely broken.

If there were N environment methods the writer of an environment subclass
would have to write N methods to support them all.  On the other hand,
if it worked in a true OO way the subclass writer would not have to write

Also suppose a new environment method comes along.  In true OO
the subclass automatically inherits it but with the "trick" the subclass
writer needs to write a new method always mimicing the parent.

This is not how OO is supposed to work.

More information about the R-devel mailing list