[R] Make functions aware of theyr own slots.

Martin Morgan mtmorgan at fhcrc.org
Sun Jun 28 05:41:55 CEST 2009


Vitalie S. wrote:
> Hello,
> 
>  Is there a way to access function's slots from inside the function? I
> want to make functions slot dependent without recurring to generic
> function mechanism.

Hi Vitalie --

See this recent thread in R-devel

  https://stat.ethz.ch/pipermail/r-devel/2009-June/053827.html

>   Probably this goes a bit against R philosophy, but otherwise I don't
> really see the use of extending functions in R.

One use is to allow for dispatch; it also provides a mechanism for
formalizing attributes that one might like to associate with functions,
e.g., their 'name'. In principle one could impose validity requirements,
e.g., that they make no reference to global variables and other
criteria, and hence are particularly suitable to parallel evaluation.

> Would be nice to have something like:
> 
> setClass("myFunc",list(type="numeric"),contains="function")
> foo<-new("myFunc",
>             function(x) me at type^x,type=0)

Really here you're applying a function to an object, which is what
generics and methods are for.

Martin

> 
> 
> Many thanks,
> Vitalie.
> 
> ______________________________________________
> 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.




More information about the R-help mailing list