From simon.urbanek at r-project.org  Tue Sep  8 18:44:15 2009
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Tue, 8 Sep 2009 12:44:15 -0400
Subject: [Rd] Reissue: Base "Object" class to use in S4 slot
	specification
In-Reply-To: <92984B14-5FA3-4080-B935-E53BBEF4FEAD@r-project.org>
References: <4A8998CD.7070708@fhcrc.org> <4AA682FB.2000201@fhcrc.org>
	<92984B14-5FA3-4080-B935-E53BBEF4FEAD@r-project.org>
Message-ID: <7F75A342-607E-4F69-B6DF-D9BA84F1B980@r-project.org>


On Sep 8, 2009, at 12:39 , Simon Urbanek wrote:

>
> On Sep 8, 2009, at 12:14 , Patrick Aboyoun wrote:
>
>> This is a reissue of a question I had asked a few weeks ago to see  
>> if anyone had any thoughts on the matter.
>>
>> I am looking to have slot in an S4 class definition that can take  
>> any (S3 or S4) object. The ANY class seemed to be a good candidate,  
>> but the is() function definition performs an S3Case test before  
>> checking if methods:::.identC(class2, "ANY"). The result is the  
>> is() function does not consider various S3 objects to be of class  
>> ANY.
>>
>
> Yes, but how is that relevant to your question? A slot defined as  
> "ANY" will accept any type in R:
>
> > setClass("foo",representation(a="ANY"))
> [1] "foo"
> > new("foo",a=factor())
> An object of class "foo"
> Slot "a":
> factor(0)
> Levels:
>
> "ANY" is not an S4 class (and neither are various other types in R),  
> so is() correctly returns FALSE.
>

Ok, sorry, the last sentence is false -  "ANY" is a virtual S4 class,  
so it will return TRUE for S4 classes and FALSE for any other object.

Cheers,
Simon


>
>
>> > is(factor(), "ANY")
>> [1] FALSE
>> > is(lm(I(1:10) ~ rnorm(10)), "ANY")
>> [1] FALSE
>> > sessionInfo()
>> R version 2.10.0 Under development (unstable) (2009-09-07 r49613)
>> i386-apple-darwin9.8.0
>>
>> locale:
>> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>> What is the recommended base "Object" class I should define my slot  
>> to be so it can accept any object?
>>
>>
>>
>> Patrick
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
>



[Rd] Reissue: Base "Object" class to use in S4 slot specification
Simon Urbanek