Hi,

as(x, "<vector-type>") is supported and does as.<vector-type>(x) for all 
vector types except for raw. For example all the following coercions 
work and do what you'd expect: as(1L, "logical"), as(1L, "double"), 
as(1L, "complex"), as(1L, "character"), as(1L, "list"). But as(1L, 
"raw") does not:

     > as(1L, "raw")
     Error in as(1L, "raw") :
       no method or default for coercing “integer” to “raw”

Even though as.raw(1L) works:

     > as.raw(1L)
     [1] 01

Is there any particular reason for that or would it be reasonable to 
define a coerce() method from ANY to raw like it's been done for all the 
other vector types:

     > selectMethod(coerce, c("ANY", "logical"))
     Method Definition:
     function (from, to, strict = TRUE)
     {
         value <- as.logical(from)
         if (strict)
             attributes(value) <- NULL
         value
     }
     <environment: namespace:methods>
     Signatures:
             from  to
     target  "ANY" "logical"
     defined "ANY" "logical"

     ...

     ...

     > selectMethod(coerce, c("ANY", "list"))
     Method Definition:
     function (from, to, strict = TRUE)
     {
         value <- as.list(from)
         if (strict)
             attributes(value) <- NULL
         value
     }
     <environment: namespace:methods>
     Signatures:
             from  to
     target  "ANY" "list"
     defined "ANY" "list"


     > selectMethod(coerce, c("ANY", "raw"))
     Error in selectMethod(coerce, c("ANY", "raw")) :
       no method found for signature ANY, raw

Thanks,

H.

-- 
Hervé Pagès

Bioconductor Core Team
hpages.on.git...@gmail.com

        [[alternative HTML version deleted]]

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

Reply via email to