From maechler at stat.math.ethz.ch  Thu Apr 24 18:37:05 2008
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Thu, 24 Apr 2008 18:37:05 +0200
Subject: [Rd] S4 default for coercing
In-Reply-To: <480F4F41.3030806@bank-banque-canada.ca>
References: <480F4F41.3030806@bank-banque-canada.ca>
Message-ID: <18448.46897.891329.719240@stat.math.ethz.ch>

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 <pgilbert at bank-banque-canada.ca>
>>>>>     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



[Rd] S4 default for coercing
Martin Maechler