I'm using an S4 object with a slot of type 'call': I would like to be able to initialize it with something like NULL or NA (indicating that there is no information in the slot) but the value should comply with the fact that it must be of type call. Is there any simple way to obtain this? Thanks for any hint, Roberto -- <r/> | Roberto Brunelli - [scientist at Fondazione Bruno Kessler-irst] | 'Home can be anywhere, for it is a part of one's self' ------------------ ITC -> dall'1 marzo 2007 Fondazione Bruno Kessler ITC -> since 1 March 2007 Fondazione Bruno Kessler
Roberto Brunelli wrote:> I'm using an S4 object with a slot of type 'call': I would like to be able to initialize > it with something like NULL or NA (indicating that there is no information in the slot) > but the value should comply with the fact that it must be of type call. > > Is there any simple way to obtain this?This looks fine: > setClass("testCall", representation = representation(call = "call")) [1] "testCall" > test <- new("testCall") > > test An object of class "testCall" Slot "call": `<undef>`() Although, I found a bug while playing around: cl <- call("round", 10.5) cl[] <- NULL cl ## CRASH using R-2.5.0 on Windows XP Uwe Ligges> Thanks for any hint, > > Roberto >
Roberto Brunelli <brunelli at itc.it> writes:> I'm using an S4 object with a slot of type 'call': I would like to > be able to initialize it with something like NULL or NA (indicating > that there is no information in the slot) but the value should > comply with the fact that it must be of type call. > > Is there any simple way to obtain this?One possibility is to create a NullCall class: setClass("NullCall", contains="call") This can be put into a slot of type 'call' and identified by its class. One advantage of this is that you can write a few methods for NullCall and in many cases avoid explicit tests like: if (class(obj) == "NullCall") ... else ... For example, you could define a show metho that printed 'NULL' or something. It is also possible to define a class union and use that as the slot type. I don't like this solution, but YMMV. + seth -- Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org