[Rd] S4 Dispatching

Paul Roebuck roebuck at odin.mdacc.tmc.edu
Tue Jul 19 22:21:10 CEST 2005


Is it possible for S4 to (continue) dispatch to a class
created during dispatching? The code below doesn't work;
is this not possible or have I ommitted something?

Concept was to create a SEXP with R_AllocatePtr, give it
a class attribute, and continue dispatch. Example code
below omits multiple parameters that can be different types.
Essentially, any parameter would be converted to an
internal type "class" and the final dispatch would be
passing EXTPTRSXP objects.


library(methods)

setGeneric("onthefly",
           function(mydata) {
    cat("generic", match.call()[[1]], "\n")
    standardGeneric("onthefly")
})

setMethod("onthefly",
          signature(mydata = "character"),
          function(mydata) {
    cat(match.call()[[1]],
        "(character)\n")

    # Simulating EXTPTRSXP
    mydata <- list(name = "mydata")
    class(mydata) <- "mydata"

    callGeneric(mydata)
})

setMethod("onthefly",
          signature(mydata = "mydata"),
          function(mydata) {
    cat(match.call()[[1]],
        "(mydata)\n")

    str(mydata)
})



> version
         _
platform powerpc-apple-darwin7.9.0
arch     powerpc
os       darwin7.9.0
system   powerpc, darwin7.9.0
status
major    2
minor    1.1
year     2005
month    06
day      20
language R

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)



More information about the R-devel mailing list