These are old utility functions to construct, respectively
a list designed to represent the slots and superclasses and
a list of prototype specifications. The
function is no longer useful, since the arguments
setClass are now recommended.
prototype() function may still be used for the
corresponding argument, but a
simple list of the same arguments works as well.
The call to representation takes arguments that are single character strings. Unnamed arguments are classes that a newly defined class extends; named arguments name the explicit slots in the new class, and specify what class each slot should have.
In the call to
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
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).
The value of
representation is just the list of arguments, after these have been checked
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).
Chambers, John M. (2008) Software for Data Analysis: Programming with R Springer. (For the R version.)
Chambers, John M. (1998) Programming with Data Springer (For the original S4 version.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
## 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") ### >>> This *is* old syntax -- use 'contains=*, slots=*' instead <<< ### ========== ---------- ------ ====== 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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.