Hi,
It doesn't seem that the dispatching algo is finding my coerce method under
some circumstances.
Let's say I have 2 classes, A and AA and that AA is just a direct extension
of A with no additional slots:
setClass("A", representation(ii="integer"))
setClass("AA", contains="A")
I can define a method for coercing my objects to an integer vector with:
setAs("A", "integer", function(from) {cat("I'm the A->integer coerce
method\n"); [EMAIL PROTECTED])
and this works as expected when my object is an AA instance:
> aa <- new("AA", ii=sample(10, 5))
> as(aa, "integer")
I'm the A->integer coerce method
[1] 10 1 6 4 7
But things don't behave that way anymore if I introduce a direct extension of
AA:
setClass("OrderedAA",
contains="AA",
validity=function(object)
{
if (!all(diff([EMAIL PROTECTED]) >= 0))
return("slot 'ii' is not ordered")
TRUE
}
)
and a method for coercing an A object to an OrderedAA object:
setAs("A", "OrderedAA",
function(from)
{
cat("I'm the A->OrderedAA coerce method\n")
new("OrderedAA", ii=sort([EMAIL PROTECTED]))
}
)
My A->OrderedAA coerce method is not called anymore:
> oaa <- as(aa, "OrderedAA")
> oaa
> validObject(oaa)
Error in validObject(oaa) :
invalid class "OrderedAA" object: slot 'ii' is not ordered
This looks like a bug to me.
Thanks,
H.
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel