getMethod              package:methods              R Documentation

_G_e_t _o_r _T_e_s_t _f_o_r _t_h_e _D_e_f_i_n_i_t_i_o_n _o_f _a _M_e_t_h_o_d

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

     The functions `getMethod' and `selectMethod' get the definition of
     a particular method; the functions `existsMethod' and `hasMethod'
     test for the existence of a method.  In both cases the first
     function only gets direct definitions and the second uses
     inheritance. The function `findMethod' returns the package(s) in
     the search list (or in the packages specified by the `where'
     argument) that contain a method for this function and signature.

     The other functions are support functions: see the details below.

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

     getMethod(f, signature=character(), where, optional=FALSE)

     findMethod(f, signature, where)

     getMethods(f, where=-1)

     existsMethod(f, signature = character(), where)

     hasMethod(f, signature=character())

     selectMethod(f, signature, optional=FALSE, useInherited,
                  mlist=getMethods(f), fdef = getGeneric(f))

     MethodsListSelect(f, env, mlist, fEnv, finalDefault, evalArgs,
                       useInherited, fdef)

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

       f: The character-string name of the generic function.

          In `getMethods' only, this argument may be a function
          definition, in which case the special methods list object, if
          any, stored in the environment of the function is returned. 
          (This usage is largely for internal purposes; you aren't
          likely to have such a function definition for direct use.)

signature: The signature of classes to match to the arguments of `f'. 
          The vector of strings for the classes should be named, and
          the names must match formal argument names of `f'.  If not
          named, the signature is assumed to apply to the arguments of
          `f' in order, but note below for `selectMethod'.

          For `selectMethod', the signature can optionally be an
          environment with classes assigned to the names of the
          corresponding arguments.  Note:  the names correspond to the
          names of the classes, not to the objects supplied in a call
          to the generic function.

   where: The position or environment in which to look for the method: 
          by default, anywhere in the current search list.

optional: If the selection does not produce a unique result, an error
          is generated, unless this argument is `TRUE'.  In that case,
          the value returned is either a `MethodsList' object, if more
          than one method matches this signature, or `NULL' if no
          method matches.

mlist, fdef: In `selectMethod', the `MethodsList' object and/or the
          generic function object can be explicitly supplied. 
          (Unlikely to be used, except in the recursive call that finds
          matches to more than one argument.)

     env: The environment in which argument evaluations are done in
          `MethodsListSelect'.  Currently must be supplied, but should
          usually be `sys.frame(sys.parent())' when calling the
          function explicitly for debugging purposes.

fEnv, finalDefault, evalArgs, useInherited: Internal-use arguments for
          the function's environment, the method to use as the overall
          default, whether to evaluate arguments, and which arguments
          should use inheritance.

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

     A call to `getMethod' returns the method for a particular function
     and signature.  As with other `get' functions, argument `where'
     controls where the function looks (by default anywhere in the
     search list) and argument `optional' controls whether the function
     returns `NULL' or generates an error if the method is not found. 
     The search for the method makes no use of inheritance.

     The function `selectMethod' also looks for a method given the
     function and signature, but makes full use of the method dispatch
     mechanism; i.e., inherited methods and group generics are taken
     into account just as they would be in dispatching a method for the
     corresponding signature, with the one exception that conditional
     inheritance is not used.  Like `getMethod', `selectMethod' returns
     `NULL' or generates an error if the method is not found, depending
     on the argument `optional'.

     The functions `existsMethod' and `hasMethod' return `TRUE' or
     `FALSE' according to whether a method is found, the first
     corresponding to `getMethod' (no inheritance) and the second to
     `selectMethod'.

     The function `getMethods' returns all the methods for a particular
     generic (in the form of a generic function with the methods
     information in its environment).  The function is called from the
     evaluator to merge method information, and is not intended to be
     called directly.

     The function `MethodsListSelect' performs a full search (including
     all inheritance and group generic information: see the Methods
     documentation page for details on how this works). The call
     returns a possibly revised methods list object, incorporating any
     method found as part of the `allMethods' slot.

     Normally you won't call `MethodsListSelect' directly, but it is
     possible to use it for debugging purposes (only for distinctly
     advanced users!).

     Note that the statement that `MethodsListSelect' corresponds to
     the selection done by the evaluator is a fact, not an assertion,
     in the sense that the evaluator code constructs and executes a
     call to `MethodsListSelect' when it does not already have a cached
     method for this generic function and signature.  (The value
     returned is stored by the evaluator so that the search is not
     required next time.)

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

     The call to `selectMethod' or `getMethod' returns a
     `MethodDefinition-class' object, the selected method, if a unique
     selection exists. (This class extends `function', so you can use
     the result directly as a function if that is what you want.)
     Otherwise an error is thrown if `optional' is `FALSE'.  If
     `optional' is `TRUE', the value returned is `NULL' if no method
     matched, or a `MethodsList' object if multiple methods matched.

     The call to `getMethods' returns the `MethodsList' object
     containing all the methods requested.  If there are none, `NULL'
     is returned: `getMethods' does not generate an error in this case.

_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.

