is                  package:methods                  R Documentation

_I_s _a_n _O_b_j_e_c_t _f_r_o_m _a _C_l_a_s_s

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

     `is':  With two arguments, tests whether `object' can be treated
     as from `class2'.

     With one argument, returns all the super-classes of this object's
     class.

     `extends':  Does the first class extend the second class? Returns
     `maybe' if the extension includes a test.

     `setIs':  Defines class1 to be an extension of class2.

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

     is(object, class2)

     extends(class1, class2, maybe=TRUE)

     setIs(class1, class2, test=NULL, coerce=NULL, replace=NULL, where=-1)

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

  object: Any R object.

class1, class2: The names of the classes between which `is' relations
          are to be defined. 

   maybe: What value to return if the relationship is conditional. 

test, coerce, replace: Functions optionally supplied to test whether
          the relation is defined, to coerce the object to `class2',
          and to alter the object so that `is(object, class2)' is
          identical to `value'. 

   where: Where to store the metadata defining the relationship.
          Default is the global environment. 

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

     `setIs': 

     The relationship can be conditional, if a function is supplied as
     the `test' argument.  If a function is supplied as the `coerce'
     argument, this function will be applied to any `class1' object in
     order to turn it into a `class2' object.

     Extension may imply that a `class1' object contains a `class2'
     object.  The default sense of containing is that all the slots of
     the simpler class are found in the more elaborate one.  If the
     `replace' argument is supplied as an S replacement function, this
     function will be used to implement `as(obj, class2) <- value'.

_A_u_t_h_o_r(_s):

     John Chambers

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

     The web page <URL: http://www.omegahat.org/RSMethods/index.html>
     is the primary documentation.

     The functions in this package emulate the facility for classes and
     methods described in Programming with Data, (John M. Chambers,
     Springer, 1998).  See this book for further details and examples.

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

     ## a class definition (see setClass for the example)
     setClass("trackCurve",
                 representation("track", smooth = "numeric"))
     ## A class similar to "trackCurve", but with different structure
     ## allowing matrices for the "y" and "smooth" slots
     setClass("trackMultiCurve", representation(x="numeric", y="matrix", smooth="matrix"),
               prototype = structure(list(), x=numeric(), y=matrix(0,0,0), smooth= matrix(0,0,0)))
     ## Define a multi-curve to extend a single curve ONLY
     ## if the y data is one variable.
     setIs("trackMultiCurve", "trackCurve", test = function(obj) {ncol(slot(obj, "y")) == 1},
           coerce = function(obj) { new("trackCurve", x = slot(obj, "x"),
             y = as.numeric(slot(obj,"y")), curve = as.numeric(slot(obj, "curve")))})

