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

Erik Iverson eriki at ccbr.umn.edu
Thu May 13 00:24:21 CEST 2010



(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



More information about the R-help mailing list