From mtmorgan at fhcrc.org  Sun Oct 22 00:23:27 2006
From: mtmorgan at fhcrc.org (Martin Morgan)
Date: Sat, 21 Oct 2006 15:23:27 -0700
Subject: [Rd] understanding virtual classes and extensions thereof
In-Reply-To: <453A3202.9040203@r-project.org> (John Chambers's message of
	"Sat, 21 Oct 2006 10:43:14 -0400")
References: <060DBDD8-C750-4BCE-BB58-FF71D1BDFA28@mac.com>
	<453A3202.9040203@r-project.org>
Message-ID: <6phk62txq8w.fsf@gopher4.fhcrc.org>



John Chambers <jmc at r-project.org> writes:

> As for:
>
> setClass("kid4", contains = "mom")
>
> this is currently a meaningless class: It's not virtual but it has no 
> meaningful prototype.  My preference would be a change that makes this a 
> virtual class, as the programmer probably intended (maybe with a warning 
> for now since it's technically a change in the API).

Maybe I misunderstand the statement about making these constructs
virtual, but I want to use 'empty' classes as predicates for method
dispatch etc. I want to be able to continue to do this:

setClass("Kid")
setClass("GoodKid", contains="Kid")
setClass("BadKid", contains="Kid")

setGeneric("deserts",
           function(object, ...) standardGeneric("deserts"))
setMethod("deserts",
          signature(object="GoodKid"),
          function(object, ...) "learn chess with dad!")
setMethod("deserts",
          signature(object="BadKid"),
          function(object, ...) "straight to bed")

I had been silently hoping that VIRTUAL would *not* be the default, so
that in the above example I could instantiate a niether good nor bad
Kid without some artifice.

Martin

> Parlamis Franklin wrote:
>> I am having some trouble creating a hierarchy of virtual classes  
>> (akin to the class structure in the 'Matrix' package).  I think they  
>> arise from my not understanding the best way to specify virtual  
>> subclasses of a virtual class.  please see questions below code.
>>
>> setClass("mom")
>>
>> setClass("kid1", representation("mom", "VIRTUAL"))
>> setClass("kid2", representation("VIRTUAL"), contains = "mom")
>> setClass("kid3"); setIs("kid3", "mom")
>>
>> (i) Are 'kid1' and 'kid2' equivalent?  I.e., is there any difference  
>> between including a superclass as an unnamed argument in the  
>> 'representation' call and including it in the 'contains' argument?   
>> If not, why does the 'contains' argument exist?
>>
>> (ii) What is the difference between 'kid1' and 'kid2', on the one  
>> hand, and 'kid3', on the other hand?  I see that 'kid1' and 'kid2'  
>> have prototypes of class 'S4', while 'kid3' has a prototype of class  
>> "NULL".  But I don't really understand the implications of that.  I  
>> am using virtual classes mostly to economize on method writing.  Will  
>> it matter on any level whether my virtual classes have NULL or S4  
>> prototypes?
>>
>> On a related note, the behavior exhibited below also seems infelicitous
>>
>> setClass("kid4", contains = "mom")
>> new("kid4")  # error in the show method
>>
>> franklin parlamis
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Martin T. Morgan
Bioconductor / Computational Biology
http://bioconductor.org




[Rd] understanding virtual classes and extensions thereof
Martin Morgan