[R] Object orientation?

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Wed Jan 24 16:39:08 CET 2001


"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...

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??)

-- 
   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