"[" not "[<-"
Prof Brian Ripley
Prof Brian Ripley <email@example.com>
Wed, 18 Nov 1998 17:59:08 +0000 (GMT)
> Date: Wed, 18 Nov 1998 18:22:23 +0100
> From: Martyn Plummer <firstname.lastname@example.org>
> To: Paul Gilbert <email@example.com>
> CC: Prof Brian Ripley <firstname.lastname@example.org>, R-devel
> Subject: Re: "[" not "[<-"
> Paul Gilbert wrote:
> > Brian Ripley writes
> > >on any of these, but it is less clear what  should do. As it is not
> > >clear if the attributes apply to the whole object only, I suspect stripping
> > >is right.
> > I have played with this some and the answer is not obvious. There are some
> > attributes it would be nice to keep and others it would be better to strip.
> > tframe attribute has to be consistent with the first dimension of the
> > it either has to be modified when the dim is modified or it has to be
> > so that there is not conflicting information. I have learned to live with
> > latter.
> Couldn't you use the object-oriented features of R? For objects of class
> "foo", subsetting can be done using the "[.foo" function. Attributes can be
> before passing the data on to NextMethod (which would strip attributes it
> know about). Then the saved attributes could be restored, possibly in a
> form, if the object is still of class "foo".
> I had assumed that this was the logic of subsetting, but it would be nice
> if someone could confirm this.
More or less (but I can only confirm my understanding of this). The
saving is not in fact needed. For example, "[.factor" does
y <- NextMethod("[")
attr(y, "contrasts") <- attr(x, "contrasts")
levels(y) <- levels(x)
etc in S. In R it does only attr(y, "levels") <- attr(x, "levels") (and I
think that is now a bug: it should preserve attr(x, "contrasts")).
I was referring to the default: Paul's example had no class.
Brian D. Ripley, email@example.com
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 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: firstname.lastname@example.org