representation()
function is no longer useful, since the arguments slots
and
contains
to setClass
are now recommended. The prototype()
function may still be used for the
corresponding argument, but a
simple list of the same arguments works as well.
representation(...)
prototype(...)
In the call to prototype
, if an unnamed argument is
supplied, it unconditionally forms the basis for the prototype
object. Remaining arguments are taken to correspond to slots of
this object. It is an error to supply more than one unnamed argument.
representation
is just the list of arguments, after these have been checked
for validity.The value of prototype
is the object to be used as the
prototype. Slots will have been set consistently with the
arguments, but the construction does not use the class
definition to test validity of the contents (it hardly can, since
the prototype object is usually supplied to create the definition).
representation
function applies tests for the validity of
the arguments. Each must specify the name of a class. The classes named don't have to exist when representation
is
called, but if they do, then the function will check for any duplicate
slot names introduced by each of the inherited classes.
The arguments to prototype
are usually named initial values
for slots, plus an optional first argument that gives the object
itself. The unnamed argument is typically useful if there is a data
part to the definition (see the examples below).
Chambers, John M. (1998) Programming with Data Springer (For the original S4 version.)
setClass
## representation for a new class with a directly define slot "smooth"
## which should be a "numeric" object, and extending class "track"
representation("track", smooth ="numeric")
setClass("Character",representation("character"))
setClass("TypedCharacter",representation("Character",type="character"),
prototype(character(0),type="plain"))
ttt <- new("TypedCharacter", "foo", type = "character")
setClass("num1", representation(comment = "character"),
contains = "numeric",
prototype = prototype(pi, comment = "Start with pi"))
Run the code above in your browser using DataLab