Skip to content
Prev 387224 / 398502 Next

Is it Possible to Create S4 Function Objects?

Hi Abby,

Something along the line of:

   setClass("S4Function",
     contains="function",
     representation(name="character", more_stuff="ANY")
   )

seems to do what you want:

   f <- new("S4Function", function(a) a^2, name="square")

   # 'f' is both an S4 object and a function:
   is.object(f)
   # [1] TRUE
   is.function(f)
   # [1] TRUE

   f at name
   # [1] "square"
   f(11)
   # [1] 121

Hope this helps,

H.
On 2/12/21 1:53 PM, Abby Spurdle (/??bi/) wrote: