Skip to content

S4 default for coercing

3 messages · Paul Gilbert, Martin Maechler, John Chambers

#
Something has changed in the S4 default for coercing.  Am I now suppose 
to use setAs, or is there something else I should do  to make this work:

R version 2.7.0 (2008-04-22)
....
 > require("methods")
 > setClassUnion("OptionalPOSIXct",   c("POSIXct",   "NULL"))
[1] "OptionalPOSIXct"
 > setClass("TSmetax",
   representation(serIDs="character", ExtractionDate="OptionalPOSIXct" ))
[1] "TSmetax"
 > setGeneric("TSmetax", def= function(x, ...) standardGeneric("TSmetax"))
[1] "TSmetax"
 > setMethod("TSmetax",   signature(x="character"),  definition= 
function(x, ...){
new("TSmetax", serIDs=x, ExtractionDate=Sys.time())  } )
[1] "TSmetax"

 > z <- new("TSmetax", serIDs="whatever", ExtractionDate= Sys.time())
Error in as(slotVal, slotClass, strict = FALSE) :
  no method or default for coercing "POSIXt" to "OptionalPOSIXct"

(It did work in R-2.6.2.)

Paul
====================================================================================

La version fran?aise suit le texte anglais.

------------------------------------------------------------------------------------

This email may contain privileged and/or confidential in...{{dropped:26}}
1 day later
#
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> 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
3 days later