[R] Defining class as a member of another class
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Sun Jun 28 08:56:45 CEST 2009
Martin Morgan wrote:
> Gabor Grothendieck wrote:
>
>> Try this:
>>
>>
>>> setClass("zoo")
>>>
>> [1] "zoo"
>>
>
> 'zoo' is I guess intended as an S3 class (from library zoo), so
> setOldClass('zoo') is appropriate. Otherwise, setClass("zoo") creates a
> new virtual class.
>
>
>>> setClass("Work",representation=(x="zoo"))
>>>
>
> This syntax representation=(x="zoo") is doing something quite strange;
>
Strange? If there's is something strange here, it's is the idea that
setClass('bar', representation=c('foo'))
creates a subclass of 'foo', while
setClass('bar', representation=c(x='foo'))
creates a class with 'foo' as a component. it's just a design choice,
but it's confusing and surely begging for trouble. but given this is as
it is, there is nothing strange with
setClass('bar', representation=(x='foo'))
as far as i am able to understand r, it's equivalent to
x = 'foo'
setClass('bar', representation='foo')
hence, bar extends foo. just a little and useless pattern.
vQ
More information about the R-help
mailing list