Skip to content
Back to formatted view

Raw Message

Message-ID: <6r8ylnt0zg.fsf@bates4.stat.wisc.edu>
Date: 2003-12-08T23:08:45Z
From: Douglas Bates
Subject: Chaining prototypes in S4 class definitions

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?