From matthias.burger at epigenomics.com  Thu Jul  3 17:26:22 2003
From: matthias.burger at epigenomics.com (Matthias Burger)
Date: Thu Jul  3 16:26:28 2003
Subject: [Rd] S4 method setClass prototype definition question
References: <news2mail-3EF86BE1.4080508@epigenomics.com>
	<3F032877.B051071E@research.bell-labs.com>
Message-ID: <3F043D0E.2030304@epigenomics.com>


John Chambers wrote:
> I think you didn't type what you meant to type (see below.)
> 
> Sourcing in your class descriptions with 1.7.1, I get what you expected.
> 


You are of course correct! Thanks for pointing this out. I should have looked 
more carefully!

[...]

Still the answer to the question on what is the recommended programming style 
for setClass definitions is not clear to me. For what purpose or in which 
circumstances should one use the 'contains' argument?
See the example code below. What side effects has it or what difference is there 
between the two versions (if any).

I would be very happy for any help gaining a clearer understanding of that 
mechanism.


Regards,


    Matthias


setClass("IDataType",
          representation("VIRTUAL",
                         valid="logical"),
          validity=NULL,
          sealed=TRUE)

##  define the parent class dependency in representation
setClass("Annotation1",
          representation ("IDataType",
                          x="vector",
                          y="vector",
                          catId="integer",
                          isResolved="logical",
                          resolve="logical"),
          prototype(isResolved=FALSE,
                    catId=as.integer(-1),
                    valid=TRUE),
          validity=NULL,
          sealed=TRUE)

##  define the dependency via a contains statement
setClass("Annotation2",
          representation (x="vector",
                          y="vector",
                          catId="integer",
                          isResolved="logical",
                          resolve="logical"),
          prototype(isResolved=FALSE,
                    catId=as.integer(-1),
                    valid=TRUE),
          contains=as.character("IDataType"),
          validity=NULL,
          sealed=TRUE)


 > an1 <- new("Annotation1")
 > an1
An object of class "Annotation1"
Slot "x":
NULL

Slot "y":
NULL

Slot "catId":
[1] -1

Slot "isResolved":
[1] FALSE

Slot "resolve":
logical(0)

Slot "valid":
[1] TRUE

 > an2 <- new("Annotation2")
 > an2
An object of class "Annotation2"
Slot "x":
NULL

Slot "y":
NULL

Slot "catId":
[1] -1

Slot "isResolved":
[1] FALSE

Slot "resolve":
logical(0)

Slot "valid":
[1] TRUE



 > all.equal(an1,an2)
[1] "Attributes: < Component 2: 1 string mismatches >"

So I conclude that appart from the class name those two objects are the same, 
and accordingly they will behave the same in all situations, won't they?




-- 
Matthias Burger

Bioinformatics R&D
Epigenomics AG                      www.epigenomics.com
Kleine Pr?sidentenstra?e 1          fax:   +49-30-24345-555
10178 Berlin Germany                phone: +49-30-24345-0


[Rd] S4 method setClass prototype definition question
Matthias Burger