From hb at stat.berkeley.edu  Wed Oct 17 16:41:27 2007
From: hb at stat.berkeley.edu (Henrik Bengtsson)
Date: Wed, 17 Oct 2007 07:41:27 -0700
Subject: [Rd] LazyLoad changes the class of objects
In-Reply-To: <Pine.LNX.4.64.0710170759210.12037@nokomis.stat.uiowa.edu>
References: <971536df0710120004k236f017je01153dcf55869dd@mail.gmail.com>
	<Pine.LNX.4.64.0710170759210.12037@nokomis.stat.uiowa.edu>
Message-ID: <59d7961d0710170741k4b25359cjdbdfcb77f772b87f@mail.gmail.com>

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.

Cheers

Henrik

On 10/17/07, Luke Tierney <luke at stat.uiowa.edu> wrote:
> Yes, attributes are not preserved, though why that should matter
> given the frequent strong recommendations in this list against
> using attributes on environments or other reference objects is
> beyond me. More importantly, locking and active bindings are not
> preserved either.  Will look into fixing this this 2.7.
>
> luke
>
> On Fri, 12 Oct 2007, Gabor Grothendieck wrote:
>
> > Consider a package that this DESCRIPTION file:
> >
> > ---
> > Package: tester
> > Version: 0.1-0
> > Date: 2007-10-12
> > Title: Prototype object-based programming
> > Author: Gabor Grothendieck
> > Maintainer: Gabor Grothendieck <ggrothendieck at gmail.com>
> > Description: test
> > LazyLoad: true
> > Depends: R (>= 2.6.0)
> > License: GPL2
> > ---
> >
> > and a single subdirectory R containing tester.R which contains two lines:
> >
> > ---
> > e <- new.env()
> > class(e) <- c("x", "environment")
> > ---
> >
> > Now issue these commands:
> >
> >> library(tester)
> >> class(tester::e)
> > [1] "environment"
> >
> >> R.version.string # Windows Vista
> > [1] "R version 2.6.0 Patched (2007-10-08 r43124)"
> >
> >
> > Note that the class of e was changed from what we set it to !!!
> >
> > On the other handn, if we omit LazyLoad: true from the DESCRIPTION file
> > then it retains its original class.
> >
> >> # removed LazyLoad: true line from DESCRIPTION and reinstall pkg
> >> # now its ok
> >> library(tester)
> >> class(tester::e)
> > [1] "x"           "environment"
> >
> > ______________________________________________
> > R-devel at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
> --
> Luke Tierney
> Chair, Statistics and Actuarial Science
> Ralph E. Wareham Professor of Mathematical Sciences
> University of Iowa                  Phone:             319-335-3386
> Department of Statistics and        Fax:               319-335-3017
>     Actuarial Science
> 241 Schaeffer Hall                  email:      luke at stat.uiowa.edu
> Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] LazyLoad changes the class of objects
Henrik Bengtsson