
92 R Programming for Bioinformatics
> setClass("W", representation(c1 = "character"))
[1] "W"
> setClass("WA", contains = (c("A", "W")))
[1] "WA"
> a1 = new("A", s1 = 20)
> w1 = new("W", c1 = "hi")
> new("WA", a1, w1)
An object of class "WA"
Slot "s1":
[1] 20
Slot "c1":
[1] "hi"
In the next example we define an initialize method that takes a value for one
of the slots and computes the value for the other, depending on the value of
the supplied argument. While we named the formal argument to the initialize
metho d b1, that was not necessary and any other name will work. However, we
find it helpful to use the slot name if the intention is that the value corresponds ...