home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Educational / R-0.49-MI / R-0.49-I / help / base / methods < prev    next >
Encoding:
Text File  |  1997-04-23  |  3.0 KB  |  78 lines

  1.     
  2.     _C_l_a_s_s _M_e_t_h_o_d_s
  3.     
  4.          UseMethod (name)
  5.          NextMethod(name, object, ...)
  6.          methods(generic.function, class)
  7.     
  8.     _D_e_s_c_r_i_p_t_i_o_n:
  9.     
  10.          R possesses a simple generic function mechanism which
  11.          can be used for an object-oriented style of program-
  12.          ming.  Method despatch takes place based on the class
  13.          of the first argument to the generic function.
  14.     
  15.          An R ``object'' is a data object which has a class
  16.          attribute.  A class attribute is a vector of character
  17.          strings giving the names of the classes which the
  18.          object ``inherits'' from.  When a generic function fun
  19.          is applied to an object with class attribute
  20.          c("first","second"), the system searches for a function
  21.          called fun.first and, if it finds it, applied it to the
  22.          object.  If no such function is found a function called
  23.          fun.second is tried.  If no class name produces a suit-
  24.          able function, the function fun.default is used.
  25.     
  26.          The function class prints the vector of names of
  27.          classes which an object inherits from.  Correspond-
  28.          ingly, class<- sets the classes which an object inher-
  29.          its from.  unclass returns (a copy of) its argument
  30.          with its class information removed.
  31.     
  32.          is.object returns TRUE if its argument has a class
  33.          attribute and FALSE otherwise.  inherits indicates
  34.          whether its first argument inherits from a class with
  35.          name equal to its second argument.
  36.     
  37.          methods can be used to find out about the methods for a
  38.          particular generic function or class.  See the examples
  39.          below for details.
  40.     
  41.          Now for some obscure details that need to appear some-
  42.          where. These comments will be slightly different than
  43.          those in Appendix A of the White S Book. UseMethod
  44.          creates a "new" function call with arguments matched as
  45.          they came in to the generic. Any local variables
  46.          defined before the call to UseMethod are retained (!?).
  47.          Any statements after the call to UseMethod will not be
  48.          evaluated as UseMethod does not return.
  49.     
  50.          NextMethod invokes the next method (determined by the
  51.          class). It does this by creating a special call frame
  52.          for that method. The arguments will be the same in
  53.          number, order and name as those to the current method
  54.          but their values will be promises to evaluate their
  55.          name in the current method and environment. Any argu-
  56.          ments matched to ... are handled specially. They are
  57.          passed on as the promise that was supplied as an argu-
  58.          ment to the current environment. (S does this dif-
  59.          ferently!) If they have been evaluated in the current
  60.          (or a previous environment) they remain evaluated.
  61.     
  62.     _N_o_t_e:
  63.     
  64.          The methods function was written by Martin Maechler.
  65.     
  66.     _S_e_e _A_l_s_o:
  67.     
  68.          class
  69.     
  70.     _E_x_a_m_p_l_e_s:
  71.     
  72.          methods(summary)
  73.          cat("methods(print):\n")
  74.          print(methods(print))
  75.          cat("methods(class = data.frame):\n")
  76.          print(methods(class = data.frame))
  77.     
  78.