Martin, I agree, if the naive changing of class (like also in Martina Morgan's simpler example below) causes issues later, it would be best if it throws an error straight away. That would have forced me to think about the correct way of changing the class immediately. I have experienced no problems with "my way" so far in my package, all methods on objects of the class in question work without trouble; but that may be due to the fact that I payed attention in the methods that slots are only used if they exist. Regards, Ulrike
> Hi, > > >>>>> "Ulrike" == Ulrike Grömping <[EMAIL PROTECTED]> > >>>>> on Fri, 23 Mar 2007 08:39:32 -0700 (PDT) writes: > > Ulrike> Martin, > > Ulrike> thank you, you've pointed me in the right direction! I just wasn't > aware > Ulrike> that a slot must not be unassigned (everything but str worked so > far, and > Ulrike> even str works in R 2.3.1). > > That "everything worked" is actually quite astonishing to me. > > I'd have expected that you should get an *error* when using > > class(<S4-object>) <- "arbitraryString" > > since - as Martin Morgan mentioned - you typically coerce > S4 objects to a new class by as(<..>, "new class") > ~~~~~~~~~~~~~~~~~~~~~ > [ which either needs an explicit SetAs(from,to, ....) > declaration ``earlier on'' (typically by one of the class > designers, often package authors), > or an implicit one - as in your case, when one class extends > another ] Simple example from Martin Morgan, how "manual change" of class attribute works: > > setClass("A", representation=representation(x="numeric")) > [1] "A" > > setClass("B", contains="A", representation=representation(y="numeric")) > [1] "B" > > a <- new("A") > > class(a) <- "B" > > str(a) > Error in FUN(c("y", "x")[[1L]], ...) : no slot of name "y" for this > object > of class "B" > > and some behavior which is somehow weird: > > > slot(a, "y") > Error in slot(a, "y") : no slot of name "y" for this object of class "B" > > slot(a, "y") <- 10 # 'creates' the slot! > > slot(a, "y") > [1] 10 ------- End of Original Message ------- [[alternative HTML version deleted]]
______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel