A couple of comments,

1.  The problem is not actually in as() but in is():

 > xx = Sys.time()
 > is(xx, "OptionalPOSIXct")
[1] FALSE
 > class(xx)
[1] "POSIXt"  "POSIXct"

  This is in fact, an "unintended" change, aka bug.  Will be fixed shortly.

2.  However, as the last line of the above should remind us all, the 
POSIX*t objects are, at the least, an interesting but unintended use of 
S3 classes, since it's the second string in the class attribute that is 
effectively the identifying class of the object.  Any treatment of the 
object in S4 will end up acting like class POSIXt.

Expecting these objects to behave properly in S4 code is an act of faith 
not likely to be rewarded in general, even though Martin's specific 
example works once the bug in is() has been fixed.

(My new book has an example of one workaround, namely to define two new 
S4 classes corresponding to POSIX[cl]t, which then extend the 
appropriate class plus POSIXt.)

All that said (and your knuckles having been rapped by Martin) thanks 
for the bug report.
  John


Martin Maechler wrote:
> Yes, there's a change from R 2.6.2 to 2.7.0  that might have
> been unintended and hence a bug.
> The short version is this
>
>   setClassUnion("OptionalPOSIXct",   c("POSIXct", "NULL"))
>
>   as(Sys.time(), "OptionalPOSIXct",  strict=FALSE)
>
> which now gives 
>    >> Error ..
>    >> no method or default for coercing "POSIXt" to "OptionalPOSIXct
>
> and used to work in 2.6.2.
> Unfortunately, the expert master mind on these issues, 
> John Chambers, is basically offline these days,
> and I'd rather have waited on his opinion on the issue.
> Class unions are a bit special and from that may have been quite
> untested.
>
> Excuse me, but why did you not find this when beta or even alpha
> testing R 2.7.0?
> We now have always 2 weeks of alpha testing and 1+1 week of beta
> testing before an x.y.0 release, 
> *EXACTLY* in order to find such issues in time and
> discuss about them {and John was around then ...}
>
> Best regards (all the same ;-),
> Martin
>
>
>
>   
>>>>>> "PaulG" == Paul Gilbert <[EMAIL PROTECTED]>
>>>>>>     on Wed, 23 Apr 2008 11:01:21 -0400 writes:
>>>>>>             
>
>     PaulG> Something has changed in the S4 default for coercing.  Am I now 
> suppose 
>     PaulG> to use setAs, or is there something else I should do  to make this 
> work:
>
>     PaulG> R version 2.7.0 (2008-04-22)
>     PaulG> ....
>     >> require("methods")
>     >> setClassUnion("OptionalPOSIXct",   c("POSIXct",   "NULL"))
>     PaulG> [1] "OptionalPOSIXct"
>     >> setClass("TSmetax",
>     PaulG> representation(serIDs="character", 
> ExtractionDate="OptionalPOSIXct" ))
>     PaulG> [1] "TSmetax"
>     >> setGeneric("TSmetax", def= function(x, ...) standardGeneric("TSmetax"))
>     PaulG> [1] "TSmetax"
>     >> setMethod("TSmetax",   signature(x="character"),  definition= 
>     PaulG> function(x, ...){
>     PaulG> new("TSmetax", serIDs=x, ExtractionDate=Sys.time())  } )
>     PaulG> [1] "TSmetax"
>
>     >> z <- new("TSmetax", serIDs="whatever", ExtractionDate= Sys.time())
>     PaulG> Error in as(slotVal, slotClass, strict = FALSE) :
>     PaulG> no method or default for coercing "POSIXt" to "OptionalPOSIXct"
>
>     PaulG> (It did work in R-2.6.2.)
>
>     PaulG> Paul
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>   

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to