Paul Bailey
2011-Jan-28 04:51 UTC
[Rd] help with S4 objects: trying to use a "link-glm" as a class in an object definition
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")> 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() ###########
Martin Morgan
2011-Jan-28 13:58 UTC
[Rd] help with S4 objects: trying to use a "link-glm" as a class in an object definition
On 01/27/2011 08:51 PM, Paul Bailey wrote:> 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"Tell the S4 system that you'd like to use this 'old' class setOldClass("link-glm") and things should be ok. Martin>> setClass("a",representation(item="link-glm")) > [1] "a" > Warning message: > undefined slot classes in definition of "a": item(class "link-glm") >> 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-- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793
Martin Maechler
2011-Jan-29 20:49 UTC
[Rd] help with S4 objects: trying to use a "link-glm" as a class in an object definition
>>>>> 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() > bAn 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