From jmc at R-project.org  Wed Jul 20 23:09:04 2005
From: jmc at R-project.org (John Chambers)
Date: Wed, 20 Jul 2005 17:09:04 -0400
Subject: [Rd] S4 Dispatching
In-Reply-To: <Pine.OSF.4.58.0507191505420.84377@odin.mdacc.tmc.edu>
References: <Pine.OSF.4.58.0507191505420.84377@odin.mdacc.tmc.edu>
Message-ID: <42DEBD70.3020009@R-project.org>

Paul Roebuck wrote:
> 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?

"doesn't work"?  This is not helpful.  Please show what you got and what 
you expected.  The result below is what I would expect (& get) from your 
code.

R> onthefly("testing")
generic onthefly
onthefly (character)
generic onthefly
onthefly (mydata)
List of 1
  $ name: chr "mydata"
  - attr(*, "class")= chr "mydata"

Since you used an undefined class "mydata" you can't expect very much 
else to work with these objects.  You did not in fact "create" the 
class, you just assigned a class attribute to an object corresponding to 
an undefined class.  There is a warning message to that effect from the 
second setMethod() call.


> 
> 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)
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] S4 Dispatching
John Chambers