[Rd] help with S4 objects: trying to use a "link-glm" as a class in an object definition

Martin Maechler maechler at stat.math.ethz.ch
Sat Jan 29 21:49:38 CET 2011


>>>>> Paul Bailey <pdbailey at umd.edu>
>>>>>     on Thu, 27 Jan 2011 23:51:21 -0500 writes:

    > Hi, I'm trying to make a new S4 object with a slot for a
    > "link-glm" object. R doesn't like me have a slot of class
    > "link-glm"

    >> class(make.link("probit"))
    > [1] "link-glm"
    >> setClass("a",representation(item="link-glm"))
    > [1] "a" Warning message: undefined slot classes in
    > definition of "a": item(class "link-glm")

you need a 

 setOldClass("link-glm")

before the the setClass() above and then things "work".

> setOldClass("link-glm")
> setClass("a",representation(item="link-glm"))
[1] "a"
> fa <- function() { new("a",item=make.link("probit"))  }
> b <- fa()
> b
An object of class "a"
Slot "item":
$linkfun
function (mu) 
....
....

Martin Maechler, ETH Zurich

    >> fa <- function() {
    > + new("a",item=make.link("probit")) + }>
    >> fa()
    > Error in validObject(.Object) : invalid class "a" object:
    > undefined class for slot "item" ("link-glm")

    > # and a link-glm looks like a list to me, so I thought I
    > would tell R it is a list and see what happens

    >> setClass("b",representation(item="list"))
    > [1] "b"
    >> fb <- function() {
    > + new("b",item=make.link("probit")) + }
    >> fb()
    > Error in validObject(.Object) : invalid class "b" object:
    > invalid object for slot "item" in class "b": got class
    > "link-glm", should be or extend class "list"

    > Any advice?

    > Regards, Paul Bailey Ph.D. candidate Department of
    > Economics University of Maryland

    > ###### raw code #####
    > setClass("a",representation(item="link-glm")) fa <-
    > function() { new("a",item=make.link("probit")) } fa()
    > setClass("b",representation(item="list")) fb <- function()
    > { new("b",item=make.link("probit")) } fb()
    > ###########
    > ______________________________________________
    > R-devel at r-project.org mailing list
    > https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list