[R] A primitive OO in R -- where next?

Liaw, Andy andy_liaw at merck.com
Thu May 13 15:05:03 CEST 2010


From: Ted.Harding at manchester.ac.uk
> 
> On 12-May-10 22:24:21, Erik Iverson wrote:
> > (Ted Harding) wrote:
> >> Greetings All,
> >> 
> >> Out of curiosity, I've just done a very primitive experiment:
> >> 
> >>   Obj <- list(Fun=sum, Dat=c(1,2,3,4))
> >>   Obj$Fun(Obj$Dat)
> >>   # [1] 10
> >> 
> >> That sort of thing (much more sophisticated) must be documented 
> >> mind-blowingly somewhere. Where?
> >> 
> >> Where I stand right now: The above (and its immediately obvious 
> >> generalisations, like Obj$Fun<-cos) is all I know about it so far.
> > 
> > Well functions are just an object in R, so lists can of 
> course contain 
> > them.  My naive understanding is that you can think of 
> function calls 
> > as simply lists where the first element is the function 
> name, and the 
> > rest of the list are the arguments, so:
> > 
> >  > eval(as.call(Obj))
> > [1] 10
> 
> Well, that's a neat trick! (It seems to depend on my having 
> put the function name first in the list, though, which wasn't 
> done with any specific intent).

This has not much to do with OO in the usual sense, just how functions
in R work.  See:
http://stat.ethz.ch/R-manual/R-devel/doc/manual/R-lang.html#Function-obj
ects

The styles of OO in S3 and S4 do not encapsulate methods into the class
definitions.

Andy 
> In fact, the sort of thing I have in mind as possible 
> applications for the idea in that simple example, is that one 
> could encapsulate a "Study" in a list, which would contain as 
> components the various datasets available (quite possibly of 
> different structures etc.), and the various functions which 
> one might use to analyse different datasets, or to combine 
> analyses, etc.; and possibly also a top-level "supervisor" 
> function which could ensure "social behaviour" in that mob of 
> entities. Pretty open-ended, really.
> 
> Ted.
> 
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 12-May-10                                       Time: 23:46:34
> ------------------------------ XFMail ------------------------------
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
Notice:  This e-mail message, together with any attachme...{{dropped:11}}



More information about the R-help mailing list