| 46973 |
ripley |
1 |
% File src/library/methods/man/findMethods.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 87282 |
maechler |
3 |
% Copyright 2008-2024 R Core Team
|
| 46973 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 44805 |
jmc |
6 |
\name{findMethods}
|
| 76021 |
maechler |
7 |
\title{Description of the Methods Defined for a Generic Function}
|
| 56186 |
murdoch |
8 |
\alias{findMethods}
|
| 44805 |
jmc |
9 |
\alias{findMethodSignatures}
|
|
|
10 |
\alias{hasMethods}
|
|
|
11 |
\alias{getMethods}
|
| 51304 |
jmc |
12 |
\alias{listOfMethods-class}
|
| 44805 |
jmc |
13 |
\description{
|
| 51304 |
jmc |
14 |
The function \code{findMethods} converts the methods defined in a table for a generic
|
| 50418 |
ripley |
15 |
function (as used for selection of methods) into a list, for study or
|
| 51304 |
jmc |
16 |
display. The list is actually from the class \code{listOfMethods}
|
| 61433 |
ripley |
17 |
(see the section describing the class, below).
|
| 44805 |
jmc |
18 |
|
| 61433 |
ripley |
19 |
|
| 51304 |
jmc |
20 |
The list will be limited
|
| 50418 |
ripley |
21 |
to the methods defined in environment \code{where} if that argument is
|
| 51304 |
jmc |
22 |
supplied and limited to those including one or more of the
|
|
|
23 |
specified \code{classes} in the method signature if that argument is
|
|
|
24 |
supplied.
|
| 44805 |
jmc |
25 |
|
| 76021 |
maechler |
26 |
To see the actual table (an \code{\link{environment}}) used
|
| 51304 |
jmc |
27 |
for methods dispatch, call \code{\link{getMethodsForDispatch}}.
|
| 76021 |
maechler |
28 |
The names of the list returned by \code{findMethods} are the names of
|
|
|
29 |
the objects in the table.
|
| 51304 |
jmc |
30 |
|
| 50418 |
ripley |
31 |
The function \code{findMethodSignatures} returns a character matrix
|
|
|
32 |
whose rows are the class names from the signature of the corresponding
|
|
|
33 |
methods; it operates either from a list returned by
|
|
|
34 |
\code{findMethods}, or by computing such a list itself, given the same
|
| 61433 |
ripley |
35 |
arguments as \code{findMethods} .
|
| 44805 |
jmc |
36 |
|
| 50418 |
ripley |
37 |
The function \code{hasMethods} returns \code{TRUE} or \code{FALSE}
|
|
|
38 |
according to whether there is a non-empty table of methods for
|
|
|
39 |
function \code{f} in the environment or search position \code{where}
|
| 51304 |
jmc |
40 |
(or for the generic function generally if \code{where} is missing).
|
| 44805 |
jmc |
41 |
|
| 87282 |
maechler |
42 |
The deprecated function \code{getMethods} (defunct for default \code{table=FALSE})
|
|
|
43 |
is an older alternative to
|
| 50418 |
ripley |
44 |
\code{findMethods} , returning information in the form of an object of
|
| 76021 |
maechler |
45 |
class \code{MethodsList}, previously used for method dispatch. This
|
|
|
46 |
class of objects is deprecated generally and will disappear in a
|
|
|
47 |
future version of R.
|
| 44805 |
jmc |
48 |
}
|
|
|
49 |
\usage{
|
| 54487 |
jmc |
50 |
findMethods(f, where, classes = character(), inherited = FALSE,
|
|
|
51 |
package = "")
|
| 51304 |
jmc |
52 |
|
| 44805 |
jmc |
53 |
findMethodSignatures(..., target = TRUE, methods = )
|
|
|
54 |
|
|
|
55 |
hasMethods(f, where, package)
|
|
|
56 |
|
| 76749 |
maechler |
57 |
## Deprecated in 2010 and defunct in 2015 for 'table = FALSE':
|
| 87282 |
maechler |
58 |
getMethods(f, where, table = FALSE) # deprecated -> use getMethodsForDispatch()
|
| 44805 |
jmc |
59 |
}
|
|
|
60 |
\arguments{
|
|
|
61 |
\item{f}{A generic function or the character-string name of one.}
|
| 50418 |
ripley |
62 |
\item{where}{Optionally, an environment or position on the search list
|
|
|
63 |
to look for methods metadata.
|
| 44805 |
jmc |
64 |
|
| 50418 |
ripley |
65 |
If \code{where} is missing, \code{findMethods} uses the current
|
|
|
66 |
table of methods in the generic function itself, and
|
|
|
67 |
\code{hasMethods} looks for metadata anywhere in the search list.
|
|
|
68 |
}
|
| 50609 |
jmc |
69 |
\item{table}{ If \code{TRUE} in a call to \code{getMethods} the
|
|
|
70 |
returned value is the table used for dispatch, including
|
|
|
71 |
inherited methods discovered to date. Used internally, but
|
|
|
72 |
since the default result is the now unused \code{mlist} object,
|
|
|
73 |
the default will likely be changed at some point.
|
|
|
74 |
}
|
| 50418 |
ripley |
75 |
\item{classes}{If supplied, only methods whose signatures contain at
|
|
|
76 |
least one of the supplied classes will be included in the value
|
|
|
77 |
returned.}
|
|
|
78 |
\item{inherited}{Logical flag; if \code{TRUE}, the table of all
|
|
|
79 |
methods, inherited or defined directly, will be used; otherwise,
|
|
|
80 |
only the methods explicitly defined. Option \code{TRUE} is
|
|
|
81 |
meaningful only if \code{where} is missing.}
|
| 44805 |
jmc |
82 |
|
| 50418 |
ripley |
83 |
\item{...}{In the call to \code{findMethodSignatures}, any arguments
|
|
|
84 |
that might be given to \code{findMethods}.}
|
|
|
85 |
\item{target}{Optional flag to \code{findMethodSignatures}; if
|
|
|
86 |
\code{TRUE}, the signatures used are the target signatures (the
|
|
|
87 |
classes for which the method will be selected); if \code{FALSE},
|
|
|
88 |
they will be the signatures are defined. The difference is only
|
|
|
89 |
meaningful if \code{inherited} is \code{TRUE}.}
|
|
|
90 |
\item{methods}{In the call to \code{findMethodSignatures}, an optional
|
|
|
91 |
list of methods, presumably returned by a previous call to
|
|
|
92 |
\code{findMethods}. If missing, that function will be call with the
|
|
|
93 |
\dots arguments.}
|
| 44805 |
jmc |
94 |
|
| 50418 |
ripley |
95 |
\item{package}{In a call to \code{hasMethods}, the package name for
|
|
|
96 |
the generic function (e.g., \code{"base"} for primitives). If
|
|
|
97 |
missing this will be inferred either from the \code{"package"}
|
|
|
98 |
attribute of the function name, if any, or from the package slot of
|
|
|
99 |
the generic function. See \sQuote{Details}.}
|
| 44805 |
jmc |
100 |
}
|
|
|
101 |
\details{
|
| 61433 |
ripley |
102 |
|
| 50418 |
ripley |
103 |
The functions obtain a table of the defined methods, either from the
|
|
|
104 |
generic function or from the stored metadata object in the environment
|
| 50609 |
jmc |
105 |
specified by \code{where}. In a call to \code{getMethods}, the information in the table is converted
|
|
|
106 |
as described above to produce the returned value, except with the
|
|
|
107 |
\code{table} argument.
|
| 44805 |
jmc |
108 |
|
| 61433 |
ripley |
109 |
|
| 50418 |
ripley |
110 |
Note that \code{hasMethods}, but not the other functions, can be used
|
|
|
111 |
even if no generic function of this name is currently found. In this
|
|
|
112 |
case \code{package} must either be supplied as an argument or included
|
|
|
113 |
as an attribute of \code{f}, since the package name is part of the
|
|
|
114 |
identification of the methods tables.
|
| 44805 |
jmc |
115 |
|
| 51304 |
jmc |
116 |
}
|
|
|
117 |
\section{The Class for lists of methods}{
|
|
|
118 |
The class \code{"listOfMethods"} returns the methods as a named list
|
|
|
119 |
of method definitions (or a primitive function, see the slot
|
|
|
120 |
documentation below). The names
|
|
|
121 |
are the strings used to store the corresponding objects in the
|
|
|
122 |
environment from which method dispatch is computed.
|
|
|
123 |
The current implementation uses the names of the corresponding classes
|
|
|
124 |
in the method signature, separated by \code{"#"} if more than one
|
|
|
125 |
argument is involved in the signature.
|
| 44805 |
jmc |
126 |
}
|
| 51304 |
jmc |
127 |
\section{Slots}{
|
|
|
128 |
|
|
|
129 |
\describe{
|
|
|
130 |
\item{\code{.Data}:}{Object of class \code{"list"} The method
|
|
|
131 |
definitions.
|
|
|
132 |
|
|
|
133 |
Note that these may include the primitive function
|
|
|
134 |
itself as default method,
|
|
|
135 |
when the generic corresponds to a primitive. (Basically, because
|
|
|
136 |
primitive functions are abnormal R objects, which cannot currently be
|
|
|
137 |
extended as method definitions.) Computations that use the returned
|
|
|
138 |
list to derive other information need to take account of this
|
|
|
139 |
possibility. See the implementation of \code{findMethodSignatures}
|
|
|
140 |
for an example.
|
|
|
141 |
}
|
|
|
142 |
\item{\code{arguments}:}{Object of class \code{"character"}. The
|
|
|
143 |
names of the formal arguments in the signature of the generic function. }
|
|
|
144 |
\item{\code{signatures}:}{Object of class \code{"list"}. A list of
|
|
|
145 |
the signatures of the individual methods. This is currently the
|
|
|
146 |
result of splitting the \code{names} according to the \code{"#"}
|
|
|
147 |
separator.
|
|
|
148 |
|
|
|
149 |
If the object has been constructed from a table, as when returned by
|
|
|
150 |
\code{findMethods}, the signatures will all have the same length.
|
|
|
151 |
However, a list rather than a character matrix is used for
|
|
|
152 |
generality. Calling \code{findMethodSignatures} as in the example
|
|
|
153 |
below will always convert to the matrix form.}
|
|
|
154 |
\item{\code{generic}:}{Object of class \code{"genericFunction"}.
|
|
|
155 |
The generic function corresponding to these methods. There
|
|
|
156 |
are plans to generalize this slot to allow reference to the function.}
|
|
|
157 |
\item{\code{names}:}{Object of class \code{"character"}. The
|
|
|
158 |
names as noted are the class names separated by \code{"#"} .}
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
\section{Extends}{
|
|
|
162 |
|
|
|
163 |
Class \code{"\linkS4class{namedList}"}, directly.
|
|
|
164 |
|
| 51322 |
hornik |
165 |
Class \code{"\linkS4class{list}"}, by class \code{"namedList"}, distance 2.
|
| 51304 |
jmc |
166 |
|
| 51322 |
hornik |
167 |
Class \code{"\linkS4class{vector}"}, by class \code{"namedList"}, distance 3.
|
| 51304 |
jmc |
168 |
}
|
|
|
169 |
|
|
|
170 |
|
| 71366 |
jmc |
171 |
\seealso{ \code{\link{showMethods}}, \code{\link{selectMethod}}, \link{Methods_Details} }
|
| 44805 |
jmc |
172 |
\examples{
|
|
|
173 |
mm <- findMethods("Ops")
|
|
|
174 |
findMethodSignatures(methods = mm)
|
|
|
175 |
}
|
|
|
176 |
\keyword{programming}
|
|
|
177 |
\keyword{classes}
|
|
|
178 |
\keyword{methods}
|