Cool, thanks a lot for the insight! I forgot that there is the option to use 'contains="VIRTUAL" and probably out of laziness usually set my virtual S4 classes simply via 'setClass("Something")'.
On 27.05.2011 15:22, Martin Morgan wrote: > On 05/27/2011 06:13 AM, Janko Thyson wrote: >> Dear list, >> >> is it possible that method dispatch checks for superclasses/virtual >> classes before checking "ANY"? >> >> I'd like to build a generic initialization method for all my Reference >> Class (say "MyDataFrame") objects by having them inherit from class, say >> "MyRefClassVirtual" (which would have to be a virtual S4 class; there >> are no virtual Reference Classes, are there?) > > Reference classes can be virtual; 'initialize' is a reference method, > not an S4 method. > > .A <- setRefClass("A", contains="VIRTUAL", > methods=list( > initialize=function(..., msg="initialize,AA") { > callSuper(...) > message(msg) > .self > })) > .AA <- setRefClass("AA", contains="A") > > > .A$new() > Error in methods::new(def, ...) : > trying to generate an object from a virtual class ("A") > > .AA$new() > initialize,AA > An object of class "AA" > <environment: 0x1b82f48> > > Martin > >> The problem is that 'getRefClass("MyDataFrame")$new' calls (I think) the >> method that was written for "ANY". Thus even though I write a explicit >> initialize method for class "MyRefClassVirtual" which I should be called >> for "MyDataFrame" as it inherits from this class, this method will never >> be called because "ANY beats anything else". >> >> So, I think I'd like to tell the method somehow to check for >> superclass/virtual classes *before* resorting to "ANY". >> >> Is that possible? >> >> Regards, >> Janko >> >> ______________________________________________ >> R-devel@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel > > -- ------------------------------------------------------------------------ *Janko Thyson* janko.thy...@googlemail.com <mailto:janko.thy...@googlemail.com> Jesuitenstraße 3 D-85049 Ingolstadt Mobile: +49 (0)176 83294257 This e-mail and any attachment is for authorized use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. [[alternative HTML version deleted]]
______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel