.Alias and memory
Prof Brian Ripley
Prof Brian Ripley <ripley@stats.ox.ac.uk>
Thu, 11 Mar 1999 11:15:05 +0000 (GMT)
> Date: Thu, 11 Mar 1999 09:37:53 +0000 (GMT)
> From: Jonathan Rougier <J.C.Rougier@durham.ac.uk>
> To: Paul Gilbert <pgilbert@bank-banque-canada.ca>
>
> On Wed, 10 Mar 1999, Paul Gilbert wrote:
>
> > In an effort to encapsulate my dependence on class in order to deal with
> > oldclass/class in Splus I defined the functions
>
> [ ... ]
>
> > This last allows me to end a function definition with
> > ...
> > classed(somecalc, "whatever") }
> >
> > rather than
> > ...
> > obj <- somecalc
> > class(obj) <- "whatever"
> > obj }
>
> I may be missing the point, but it seems to me that you could achieve a
> `one-line return' using
>
> structure(somecalc, class = "whatever")
>
> which would also avoid passing somecalc into another function.
In part you are. That is equivalent to
attr(somecalc, "class") <- "whatever"
and whereas that happens to be how class<- is defined on S3 and R, it
is not how it works in S-PLUS 5 (although oldClass<- is currently
defined that way). When you want to change to S-PLUS 5-style classes
you have to remember that you have subverted the system!
More generally, using the representation not the public method in
object-oriented programming is a recipe for disaster.
--
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 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: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._