In an effort to encapsulate my dependence on class in order to deal with oldclass/class in Splus I defined the functions tfclass <- class "tfclass<-" <- function(x, value){ class(x) <- value ; x } and also the function classed <- function(x, cls) {class(x) <- cls; x} This last allows me to end a function definition with ... classed(somecalc, "whatever") } rather than ... obj <- somecalc class(obj) <- "whatever" obj } Unfortunately, these seem to increase my memory usage in R substantially. Using tfclass <- .Alias(class) "tfclass<-" <- .Alias(get("class<-")) helps a bit. Is there a better overall approach to this that avoids increasing the memory demands? Paul Gilbert -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi Paul, 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. Cheers, Jonathan. Jonathan Rougier Science Laboratories Department of Mathematical Sciences South Road University of Durham Durham DH1 3LE "[B]egin upon the precept ... that the things we see are to be weighed in the scale with what we know" (Meredith, 1879, The Egoist) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._