From roebuck at odin.mdacc.tmc.edu  Fri Aug  5 10:09:51 2005
From: roebuck at odin.mdacc.tmc.edu (Paul Roebuck)
Date: Fri, 5 Aug 2005 03:09:51 -0500 (CDT)
Subject: [Rd] S4 generating function
Message-ID: <Pine.OSF.4.58.0508050253370.278029@odin.mdacc.tmc.edu>

Can someone explain what the problem is when I use the
generating function? And how to get debug() to stop in
the Superclass initialize method?


---- source -----
setClass("Superclass",
         representation(id = "character"),
         contains = "VIRTUAL")

setMethod("initialize",
          signature(.Object = "Superclass"),
          function(.Object, id = "") {
              cat("initialize (Superclass)", "\n")
              if (length(id) > 0) {
                  cat("\tid =", id, "\n")
                  .Object at id <- id
              }
              .Object
          })

setClass("Subclass",
         contains = "Superclass")

setMethod("initialize",
          signature(.Object = "Subclass"),
          function(.Object, ...) {
              cat("initialize (Subclass)", "\n")
              cat("\t... =");str(list(...));cat("\n")
              callNextMethod(.Object, ...)
          })

Subclass <- function(id = "") {
    new("Subclass", id = id)
}

cat("*** Create class using new() ***\n")
str(new("Subclass", id = "test1"))

cat("*** Create class using generating function ***\n")
str(Subclass(id = "test2"))


---- output -----
*** Create class using new() ***
initialize (Subclass)
        ... =List of 1
 $ id: chr "test1"

initialize (Superclass)
        id = test1
Formal class 'Subclass' [package ".GlobalEnv"] with 1 slots
  ..@ id: chr "test1"
*** Create class using generating function ***
initialize (Subclass)
        ... =List of 1
 $ id: chr "test2"

initialize (Superclass)
Error in .local(.Object, ...) : Object "id" not found


Thanks

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



[Rd] S4 generating function
Paul Roebuck