StructureClasses           package:methods           R Documentation

_C_l_a_s_s_e_s _C_o_r_r_e_s_p_o_n_d_i_n_g _t_o _B_a_s_i_c _S_t_r_u_c_t_u_r_e_s

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

     The virtual class 'structure' and classes that extend it are
     formal classes analogous to S language structures such as arrays
     and time-series.

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

     ## The following class names can appear in method signatures,
     ## as the class in as() and is() expressions, and, except for
     ## the classes commented as VIRTUAL, in calls to new()

     "matrix"
     "array"
     "ts"

     "structure" ## VIRTUAL

_O_b_j_e_c_t_s _f_r_o_m _t_h_e _C_l_a_s_s_e_s:

     Objects can be created by calls of the form 'new(Class, ...)',
     where 'Class' is the quoted name of the specific class (e.g.,
     '"matrix"'), and the other arguments, if any, are interpreted as
     arguments to the corresponding function, e.g., to function
     'matrix()'.  There is no particular advantage over calling those
     functions directly, unless you are writing software designed to
     work for multiple classes, perhaps with the class name and the
     arguments passed in.

     Objects created from the classes '"matrix"' and '"array"' are
     unusual, to put it mildly, and have been for some time.  Although
     they may appear to be objects from these classes, they do not have
     the internal structure of either an S3 or S4 class object.  In
     particular, they have no '"class"' attribute and are not
     recognized as objects with classes (that is, both 'is.object' and
     'isS4' will return 'FALSE' for such objects).

     That the objects still behave as if they came from the
     corresponding class (most of the time, anyway) results from
     special code recognizing such objects being built into the base
     code of R. For most purposes, treating the classes in the usual
     way will work, fortunately.  One consequence of the special
     treatment is that these two classes_may_ be used as the data part
     of an S4 class; for example, you can get away with 'contains =
     "matrix"' in a call to 'setGeneric' to create an S4 class that is
     a subclass of '"matrix"'.  There is no guarantee that everything
     will work perfectly, but a number of classes have been written in
     this form successfully.

     The class '"ts"'  is basically an S3 class that has been
     registered with S4, using the 'setOldClass' mechanism.  Versions
     of R through 2.7.0 treated this class as a pure S4 class, which
     was in principal a good idea, but in practice did not allow
     subclasses to be defined and had other intrinsic problems.  (For
     example, setting the '"tsp"' parameters as a slot often fails
     because the built-in implementation does not allow the slot to be
     temporarily inconsistent with the length of the data. Also, the S4
     class prevented the correct specification of the S3 inheritance
     for class '"mts"'.)

     The current behavior (beginning with version 2.8.0 of R) registers
     '"ts"' as an S3 class,  using an S4-style definition (see the
     documentation for 'setOldClass' in the examples section for an
     abbreviated listing of how this is done.  The S3 inheritance of
     '"mts"' in package 'stats' is also registered. These classes, as
     well as '"matrix"' and '"array"' should be valid in most examples
     as superclasses for new S4 class definitions.

_E_x_t_e_n_d_s:

     The specific classes all extend class '"structure"', directly, and
     class '"vector"', by class '"structure"'.

_M_e_t_h_o_d_s:


     _c_o_e_r_c_e Methods are defined to coerce arbitrary objects to these
          classes, by calling the corresponding basic function, for
          example, 'as(x, "matrix")' calls 'as.matrix(x)'.

     _O_p_s, _M_a_t_h Group methods (see, e.g., 'S4groupGeneric') are defined
          for combinations of structures and vectors (including special
          cases for array and matrix), implementing the concept of
          vector structures as in the reference.


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

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

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole (for the original vector
     structures).

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

     showClass("structure")

     ## explore a bit :
     showClass("ts")
     (ts0 <- new("ts"))
     str(ts0)

     showMethods("Ops") # six methods from these classes, but maybe many more

