Simon,
I don't want to get too deep into specific implementations here so we
don't get stuck in the weeds. (The original issue started with a typed
list class infrastructure in BioC's IRanges package that checked to see
if the elements conformed to the expected class.)
To make this issue as narrow as possible for now, I'll rephrase my issue
to be inconsistent behavior between is and extends for class ANY. All
classes (even non-existent ones) extend ANY according to
methods::extends, but only S4 objects are of class ANY according to
methods::is. This could be reconciled if is() checked if
methods:::.identC(class2, "ANY") before it performed an S3Case test.
> is(factor(), "ANY")
[1] FALSE
> extends("factor", "ANY")
[1] TRUE
> is(lm(I(1:10) ~ rnorm(10)), "ANY")
[1] FALSE
> extends("lm", "ANY")
[1] TRUE
> 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
Patrick
Simon Urbanek wrote:
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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel