representation            package:methods            R Documentation

_C_o_n_s_t_r_u_c_t _a  _R_e_p_r_e_s_e_n_t_a_t_i_o_n _o_r _a _P_r_o_t_o_t_y_p_e _f_o_r _a _C_l_a_s_s _D_e_f_i_n_i_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     In calls to 'setClass', these two functions construct,
     respectively, the 'representation' and 'prototype' arguments. 
     They do various checks and handle special cases.  You're
     encouraged to use them when defining classes that, for example,
     extend other classes as a data part or have multiple superclasses,
     or that combine extending a class and slots.

_U_s_a_g_e:

     representation(...)
     prototype(...)

_A_r_g_u_m_e_n_t_s:

     ...: 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 '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. 

_D_e_t_a_i_l_s:

     The '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).

_V_a_l_u_e:

     The value pf '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).

_R_e_f_e_r_e_n_c_e_s:

     The R package 'methods' implements, with a few exceptions, the
     programming interface for classes and methods in the book
     _Programming with Data_ (John M. Chambers, Springer, 1998), in
     particular sections 1.6, 2.7, 2.8, and chapters 7 and 8.

     While the programming interface for the 'methods' package follows
     the reference, the R software is an original implementation, so
     details in the reference that reflect the S4 implementation may
     appear differently in R.  Also, there are extensions to the
     programming interface developed more recently than the reference. 
     For a discussion of details and ongoing development, see the web
     page  <URL: http://developer.r-project.org/methodsPackage.html>
     and the pointers from that page.

_S_e_e _A_l_s_o:

     'setClass'

_E_x_a_m_p_l_e_s:

     ## 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"))

