[Rd] S4 generating function

From: Paul Roebuck <roebuck_at_odin.mdacc.tmc.edu>
Date: Fri 05 Aug 2005 - 08:09:51 GMT


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?

setMethod("initialize",

          signature(.Object = "Superclass"),
          function(.Object, id = "") {
              cat("initialize (Superclass)", "\n")
              if (length(id) > 0) {
                  cat("\tid =", id, "\n")
                  .Object@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"))

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)

R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri Aug 05 18:12:58 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:16 GMT