Skip to content
Prev 17132 / 63421 Next

S4 generating function

On Fri, 5 Aug 2005, John Chambers wrote:

            
Thank you for your help. Unfortunately, this is a case where
posting the simplest code necessary to display the bug works
against the poster. Actual code uses external pointers but
this revision shows more of the general concept.

If I understand your description correctly, the problem is
passing both named and unnamed arguments to callNextMethod().
Can I [easily] do either of these things to avoid the bug?

  1) somehow add an argument to 'dots' and invoke callNextMethod()
     without arguments?
  2) parse 'dots' and invoke callNextMethod() with a completely
     named argument list?


------ revised source -------
setClass("Superclass",
         representation(.values = "integer",
                        id      = "character"),
         contains = "VIRTUAL")

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

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

setMethod("initialize",
          signature(.Object = "Subclass"),
          function(.Object, count = 1, ...) {
              cat("initialize (Subclass)", "\n")
              dots <- list(...)
              cat("\t... =");str(dots);cat("\n")
              .values = integer(count)
              callNextMethod(.Object, .values = .values, ...)
          })

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

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

cat("*** Create class using generating function ***\n")
#trace("initialize", signature = "Subclass", browser)
str(Subclass(count = 3, id = "test2"))

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