From bates at stat.wisc.edu  Mon Dec  8 23:10:11 2003
From: bates at stat.wisc.edu (Douglas Bates)
Date: Mon Dec  8 23:08:45 2003
Subject: [Rd] Chaining prototypes in S4 class definitions
Message-ID: <6r8ylnt0zg.fsf@bates4.stat.wisc.edu>

Under R-devel class definitions like

# S4 class for general double-precision matrices
setClass("Matrix",
         representation(Dim = "integer", rcond = "numeric",
                        factorization = "list"),
         contains = "numeric",
         prototype = prototype(numeric(0), Dim = as.integer(c(0,0)),
         rcond = as.numeric(NA), factorization = list()),
         validity = function(object) {
             .Call("Matrix_validate", object, PACKAGE="Matrix")
         })

# Dense, non-packed, triangular matrices 
setClass("trMatrix",
         representation(uplo = "character", diag = "character"),
         contains = "Matrix",
         prototype = prototype(new("Matrix"), uplo = "U", diag = "N"),
         validity = function(object) {
             .Call("trMatrix_validate", object, PACKAGE="Matrix")
         })

generate an error

Error in makePrototypeFromClassDef(properties, ClassDef, immediate) : 
	In constructing the prototype for class "trMatrix": Prototype has class "Matrix", but the data part specifies class "numeric"

which makes sense.  Is there a way to chain the definition of the
prototype so that a prototype object of the contained class is
generated first then the additional slots are added?


[Rd] Chaining prototypes in S4 class definitions
Douglas Bates