Skip to content
Prev 387263 / 398502 Next

Is it Possible to Create S4 Function Objects?

I've completed the S4 example.
Thank you, Herve, for your assistance.

----begin code----
plotf <- function (f)
{   x <- seq (-1, 1,, 200)
    plot (x, f (x), type="l")
}

#s4-based function object, with slot
setClass ("Quad.S4", contains="function", slots = list (p="numeric") )
Quad.S4 <- function (p = c (0, 0, 1) )
{   f <- function (x)
    {   this <- sys.function ()
        p <- this at p
        p [1] + p [2] * x + p [3] * x^2
    }
    new ("Quad.S4", f, p=p)
}

f.s4 <- Quad.S4 ()
plotf (f.s4)
f.s4 at p


On Tue, Feb 23, 2021 at 11:23 AM Abby Spurdle (/??bi/)
<spurdle.a at gmail.com> wrote: