[R] Object orientation?

Yves Gauvreau cyg at sympatico.ca
Wed Jan 24 17:45:20 CET 2001

> -----Message d'origine-----
> De : pd at blueberry.kubism.ku.dk [mailto:pd at blueberry.kubism.ku.dk]De la
> part de Peter Dalgaard BSA
> Envoye : Wednesday, January 24, 2001 10:39 AM
> A : Yves Gauvreau
> Cc : R-help at lists. R-project. org
> Objet : Re: [R] Object orientation?
> "Yves Gauvreau" <cyg at sympatico.ca> writes:
> > Up to now there is no real problem as I could use the following
> construct
> > for these let and set methods or functions: MyO <-
> > MyO.let(PropertyName="ThisProperty", ThisValue).
> >
> > But what I would like to be able to do in order to let or set
> (as above) one
> > of MyO properties for example is only use:
> > MyO.let(PropertyName="ThisProperty", ThisValue).
> >
> > So my question is: Can this be done in a proper and acceptable
> R fashion?
> >
> > I know I could use super assign (<<-) but I think some say it's best
> > avoided.
> Generally, that's when people try to turn R (or S) into a macro
> language. There could be situations where it's the right thing...

Could you be so kind as to explain what you mean by "turn R (or S) into a
macro language"

> However, for this situation, how about something like
> class(MyO) <- "foo"
> "$<-.foo" <- function(x, name, value)
> {
>    if ( !is.null(x$let) )
> 	x$let(PropertyName=name, value)
>    else
> 	x[[name]] <- value
> }
> MyO$ThisProperty <- ThisValue
> (but wouldn't x$let or MyO.let need to have some way of figuring out
> which object is its owner??)

Maybe the way I expressed the idea wasn't clear enough or the way I
expressed it wasn't, so I'll try again. I have a personal project where I
would like to use R for it's statistical and graphical capabilities as is
usually the case presumably.

The strategy I thought up would probably be better handled (or easier to
implement) with an object orientation kind of approach. I was able to
identify many objects, in the since of OOP terminology, which would also
need to be handle as a group or as a collection (or as some kind of a
list|data.frame in R terms). I would also require a few of these groups to
be imbedded in higher level object and so on. My first idea was to imbed R
in a program written in a language like C++ for example. Before I start
working in this manner, I thought of investigating the possibilities of
doing all of this in R instead. So I bought "S Programming" from Venables &
Ripley and read it along with other material. So in the process I kind of
ask myself the same thing as you ask me above and I've got no answer. Maybe
I should of ask what are the facilities in R to write or implement an
hierarchy of object (classes) working together as in C++ or as close as
possible to that?



PS I take this occasion to thank all other who tried to help as well.

> --
>    O__  ---- Peter Dalgaard             Blegdamsvej 3
>   c/ /'_ --- Dept. of Biostatistics     2200 Cph. N
>  (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907

r-help 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-help-request at stat.math.ethz.ch

More information about the R-help mailing list