setClass
Define or Re-Define a Class of Objects

Description

Define a new class or re-define an existing class.

Usage

setClass(Class, representation = list(), prototype = NULL,
         contains = character(), validity = NULL, access = list(),
         where = topenv(parent.frame()), version = .newExternalptr(),
         sealed = FALSE, package = getPackageName(where),
         S3methods = FALSE, slots) 

Arguments

Class a character string name of the class to be defined.
representation the representation for the class, including slot names and classes, and any contained classes. If representation is given, it should be a class representation (for example, a call to the function representation), although the name of a single class is a valid short form.
prototype the object to be used as the initial prototype. The function new takes this object and sets its class to Class.
contains a string vector of class names for the superclasses of this new class.
validity an optional function of one argument for testing the validity of an object from the class. It should return TRUE if its argument is a valid object from Class, or a character string describing the problem otherwise. This is called by the validObject function, which is called from new().
access this argument is unimplemented, and a warning is generated if it is given.
where this argument is unimplemented, and a warning is generated if it is given.
version this argument is unimplemented, and a warning is generated if it is given.
sealed this argument is unimplemented, and a warning is generated if it is given.
package this argument is unimplemented, and a warning is generated if it is given.
S3methods this argument is unimplemented, and a warning is generated if it is given.
slots a list of strings or a character vector, specifying the slots for this class. The names of the list or vector are the slot names, and the elements are the slot classes. If an element has no name, the value is used as the slot name, and the class is "ANY". If this argument and the representation argument are both specified, this produces an error.
Value
returns a function of class classGeneratorFunction, which can be called to create an object of the class. This is similar to calling the new function.
See Also
getClass, isClass.
Examples
## a class with two numeric slots 
setClass("track", representation(x="numeric", y="numeric")) 
## a class extending "matrix", with one new slot, and a validity method 
setClass("tsMatrix", representation("matrix", tsp = "numeric"), 
   validity = function(x) nrow(x) == length(x@tsp)) 
## a class extending "tsMatrix" with no additional slots 
setClass("tsMatrix2", "tsMatrix") 
## using the 'slots' argument to specify slots
setClass("track2", slots=c(x="numeric", y="numeric"))
Package methods version 6.1.4-13
Package Index