[Rd] Chaining prototypes in S4 class definitions

Douglas Bates bates at stat.wisc.edu
Mon Dec 8 23:10:11 MET 2003


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?



More information about the R-devel mailing list