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