The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/methods/man/MethodsList.Rd
2
% Part of the R package, http://www.R-project.org
59039 ripley 3
% Copyright 1995-2007 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
15357 jmc 6
\name{MethodsList}
56186 murdoch 7
\alias{MethodsList}
15357 jmc 8
\alias{makeMethodsList}
9
\alias{SignatureMethod}
10
\alias{insertMethod}
20092 jmc 11
\alias{inheritedSubMethodLists}
15357 jmc 12
\alias{showMlist}
13
\alias{print.MethodsList}
16066 jmc 14
\alias{emptyMethodsList}
15
\alias{insertMethodInEmptyList}
16447 jmc 16
\alias{listFromMlist}
16764 jmc 17
\alias{linearizeMlist}
16471 jmc 18
\alias{finalDefaultMethod}
19
\alias{mergeMethods}
18558 jmc 20
\alias{loadMethod}
25816 jmc 21
\alias{loadMethod-methods}
22
\alias{loadMethod,ANY-method}
23
\alias{loadMethod,MethodDefinition-method}
24
\alias{loadMethod,MethodWithNext-method}
44805 jmc 25
\alias{MethodsListSelect}
15357 jmc 26
\title{MethodsList Objects}
18994 hornik 27
\description{
28
  These functions create and manipulate \code{MethodsList} objects, the
44805 jmc 29
  objects formerly used in R to store methods for dispatch.  Use of
30
  these objects is no longer required, and while not yet formally
31
  deprecated, will rarely be a good idea.  Where methods dispatch is
32
  to be studied, see \code{\link{selectMethod}}.  For computations
33
  that iterate over methods or over method signatures, see
34
  \code{\link{findMethods}}, which returns a linearized methods list
35
  to hold method definitions, usually more convenient for iteration
36
  than the recursive \code{MethodsList} objects.
18994 hornik 37
}
15357 jmc 38
\usage{
39
MethodsList(.ArgName, ...)
40
 
41
makeMethodsList(object, level=1)
42
 
43
SignatureMethod(names, signature, definition)
44
 
21345 jmc 45
insertMethod(mlist, signature, args, def, cacheOnly)
15357 jmc 46
 
20092 jmc 47
inheritedSubMethodLists(object, thisClass, mlist, ev)
15357 jmc 48
 
16802 jmc 49
showMlist(mlist, includeDefs = TRUE, inherited = TRUE,
17000 jmc 50
   classes, useArgNames, printTo = stdout() )
15357 jmc 51
 
25433 hornik 52
\method{print}{MethodsList}(x, ...)
15357 jmc 53
 
41739 maechler 54
listFromMlist(mlist, prefix = list(), sigs. = TRUE, methods. = TRUE)
16447 jmc 55
 
16802 jmc 56
linearizeMlist(mlist, inherited = TRUE)
16302 jmc 57
 
51427 jmc 58
finalDefaultMethod(method)
16471 jmc 59
 
22464 jmc 60
mergeMethods(m1, m2, genericLabel)
16471 jmc 61
 
18558 jmc 62
loadMethod(method, fname, envir)
63
 
44805 jmc 64
MethodsListSelect(f, env, mlist, fEnv, finalDefault, evalArgs,
65
                  useInherited, fdef, resetAllowed)
66
 
15357 jmc 67
}
17454 jmc 68
 
69
\section{Details}{
70
 
18994 hornik 71
  \describe{
21353 maechler 72
 
73
    \item{\code{MethodsList}:}{
18994 hornik 74
      Create a MethodsList object out of the arguments.
15357 jmc 75
 
18994 hornik 76
      Conceptually, this object is a named collection of methods to be
77
      dispatched when the (first) argument in a function call matches
78
      the class corresponding to one of the names.  A final, unnamed
79
      element (i.e., with name \code{""}) corresponds to the default
80
      method.
15357 jmc 81
 
18994 hornik 82
      The elements can be either a function, or another MethodsList.  In
83
      the second case, this list implies dispatching on the second
84
      argument to the function using that list, given a selection of
85
      this element on the first argument.  Thus, method dispatching on
86
      an arbitrary number of arguments is defined.
15357 jmc 87
 
18994 hornik 88
      MethodsList objects are used primarily to dispatch OOP-style
89
      methods and, in R, to emulate S4-style methods.
90
    }
15357 jmc 91
 
21353 maechler 92
    \item{\code{SignatureMethod}:}{
18994 hornik 93
      construct a MethodsList object containing (only) this method,
19029 hornik 94
      corresponding to the signature; i.e., such that
95
      \code{signature[[1]]} is the match for the first argument,
96
      \code{signature[[2]]} for the second argument, and so on.  The
97
      string \code{"missing"} means a match for a missing argument, and
98
      \code{"ANY"} means use this as the default setting at this level.
15357 jmc 99
 
18994 hornik 100
      The first argument is the argument names to be used for dispatch
101
      corresponding to the signatures.
102
    }
15357 jmc 103
 
21353 maechler 104
    \item{\code{insertMethod}:}{
18994 hornik 105
      insert the definition \code{def} into the MethodsList object,
106
      \code{mlist}, corresponding to the signature.  By default, insert
21353 maechler 107
      it in the slot \code{"methods"}, but \code{cacheOnly=TRUE} inserts
108
      it into the \code{"allMethods"} slot (used for dispatch but not saved).
18994 hornik 109
    }
15357 jmc 110
 
21353 maechler 111
    \item{\code{inheritedSubMethodLists}:}{
18994 hornik 112
      Utility function to match the object  or the class (if the object
113
      is \code{NULL}) to the elements of a methods list.
114
      Used in finding inherited methods, and not meant to be called
115
      directly.
116
    }
15357 jmc 117
 
21353 maechler 118
    \item{\code{showMlist}:}{
18994 hornik 119
      Prints the contents of the MethodsList.  If \code{includeDefs} the
40281 ripley 120
      signatures and the corresponding definitions will be printed;
18994 hornik 121
      otherwise, only the signatures.
35205 maechler 122
    }
15357 jmc 123
 
35205 maechler 124
    \item{\code{listFromMlist}:}{
125
      Undo the recursive nature of the methods list, making a list of
41739 maechler 126
      \code{list(sigs,methods)} of function definitions, i.e. of
127
      matching signatures and methods.
35205 maechler 128
      \code{prefix} is the partial signature (a named list of classes)
41739 maechler 129
      to be prepended to the signatures in this object.  If \code{sigs.}
130
      or \code{methods.} are \code{FALSE}, the resulting part of the
131
      return value will be empty.
35205 maechler 132
 
133
      A utility function used to iterate over all the individual methods
134
      in the object, it calls itself recursively.
18994 hornik 135
    }
21353 maechler 136
 
35205 maechler 137
    \item{\code{linearizeMlist}:}{
18994 hornik 138
      Undo the recursive nature of the methods list, making a list of
35205 maechler 139
      function definitions, with the names of the list being the
140
      corresponding signatures.
21353 maechler 141
 
35205 maechler 142
      Designed for printing; for looping over the methods, use the above
143
      \code{listFromMlist} instead.
18994 hornik 144
    }
16302 jmc 145
 
18994 hornik 146
    \item{\code{finalDefaultMethod}:}{
51427 jmc 147
      The default method or NULL.  With the demise of
148
      \code{"MethodsList"} objects, this function only checks that the
149
      value given it is a method definition, primitive or NULL.
18994 hornik 150
    }
16471 jmc 151
 
18994 hornik 152
    \item{\code{mergeMethods}:}{
153
      Merges the methods in the second MethodsList object into the
154
      first, and returns the merged result.  Called from
22594 ripley 155
      \code{\link{getAllMethods}}.  For a primitive function,
156
      \code{genericLabel} is supplied as the name of the generic.
16471 jmc 157
    }
18994 hornik 158
 
159
    \item{\code{loadMethod}:}{
18558 jmc 160
      Called, if necessary, just before a call to \code{method} is
161
      dispatched in the frame \code{envir}.  The function exists so that
162
      methods can be defined for special classes of objects.  Usually
163
      the point is to assign or modify information in the frame
164
      environment to be used evaluation.  For example, the standard
165
      class \code{MethodDefinition} has a method that stores the target
25816 jmc 166
      and defined signatures in the environment.  Class
167
      \code{MethodWithNext} has a method taking account of the
168
      mechanism for storing the method to be used in a call to
169
      \code{\link{callNextMethod}}.
18558 jmc 170
 
171
      Any methods defined for \code{loadMethod} must return the function
172
      definition to be used for this call; typically, this is just the
173
      \code{method} argument.
18994 hornik 174
    }
44805 jmc 175
 
176
  \item{\code{MethodsListSelect}}{
177
      The function \code{MethodsListSelect} performs a full search
178
      (including all inheritance and group generic information: see the
179
      \link{Methods} documentation page for details on how this works).
180
      The call returns a possibly revised methods list object,
181
      incorporating any method found as part of the \code{allMethods}
182
      slot.  This search was used by the evaluator when methods lists
183
      were the metadata for methods dispatch.  This function is now deprecated.
184
 
185
    }
18994 hornik 186
  }
16066 jmc 187
}
44585 maechler 188
\note{
15357 jmc 189
  Note that \code{MethodsList} objects represent methods only in the \R
190
  implementation.  You can use them to find or manipulate information about
191
  methods, but avoid doing so if you want your code to port to S-Plus.
192
}
193
\references{
46128 jmc 194
 Chambers, John M. (2008)
195
 \emph{Software for Data Analysis: Programming with R}
196
  Springer.  (For the R version.)
15357 jmc 197
 
46128 jmc 198
 Chambers, John M. (1998)
199
 \emph{Programming with Data}
200
 Springer (For the original S4 version.)
15357 jmc 201
}
16471 jmc 202
\keyword{internal}
203