The R Project SVN R

Rev

Rev 76021 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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