findMethods {methods} | R Documentation |
The function findMethods
converts the methods defined in a table for a generic
function (as used for selection of methods) into a list, for study or
display. The list is actually from the class listOfMethods
(see the section describing the class, below).
The list will be limited
to the methods defined in environment where
if that argument is
supplied and limited to those including one or more of the
specified classes
in the method signature if that argument is
supplied.
To see the actual table (an environment) used
for methods dispatch, call getMethodsForDispatch
.
The names of the list returned by findMethods
are the names of
the objects in the table.
The function findMethodSignatures
returns a character matrix
whose rows are the class names from the signature of the corresponding
methods; it operates either from a list returned by
findMethods
, or by computing such a list itself, given the same
arguments as findMethods
.
The function hasMethods
returns TRUE
or FALSE
according to whether there is a non-empty table of methods for
function f
in the environment or search position where
(or for the generic function generally if where
is missing).
The defunct function getMethods
is an older alternative to
findMethods
, returning information in the form of an object of
class MethodsList
, previously used for method dispatch. It is
not recommended, since this class of objects is deprecated generally
and will disappear in a future version of R.
findMethods(f, where, classes = character(), inherited = FALSE, package = "") findMethodSignatures(..., target = TRUE, methods = ) hasMethods(f, where, package) ## Deprecated in 2010 and defunct in 2015 for \code{table = FALSE}: getMethods(f, where, table = FALSE)
f |
A generic function or the character-string name of one. |
where |
Optionally, an environment or position on the search list to look for methods metadata. If |
table |
If |
classes |
If supplied, only methods whose signatures contain at least one of the supplied classes will be included in the value returned. |
inherited |
Logical flag; if |
... |
In the call to |
target |
Optional flag to |
methods |
In the call to |
package |
In a call to |
The functions obtain a table of the defined methods, either from the
generic function or from the stored metadata object in the environment
specified by where
. In a call to getMethods
, the information in the table is converted
as described above to produce the returned value, except with the
table
argument.
Note that hasMethods
, but not the other functions, can be used
even if no generic function of this name is currently found. In this
case package
must either be supplied as an argument or included
as an attribute of f
, since the package name is part of the
identification of the methods tables.
The class "listOfMethods"
returns the methods as a named list
of method definitions (or a primitive function, see the slot
documentation below). The names
are the strings used to store the corresponding objects in the
environment from which method dispatch is computed.
The current implementation uses the names of the corresponding classes
in the method signature, separated by "#"
if more than one
argument is involved in the signature.
.Data
:Object of class "list"
The method
definitions.
Note that these may include the primitive function
itself as default method,
when the generic corresponds to a primitive. (Basically, because
primitive functions are abnormal R objects, which cannot currently be
extended as method definitions.) Computations that use the returned
list to derive other information need to take account of this
possibility. See the implementation of findMethodSignatures
for an example.
arguments
:Object of class "character"
. The
names of the formal arguments in the signature of the generic function.
signatures
:Object of class "list"
. A list of
the signatures of the individual methods. This is currently the
result of splitting the names
according to the "#"
separator.
If the object has been constructed from a table, as when returned by
findMethods
, the signatures will all have the same length.
However, a list rather than a character matrix is used for
generality. Calling findMethodSignatures
as in the example
below will always convert to the matrix form.
generic
:Object of class "genericFunction"
.
The generic function corresponding to these methods. There
are plans to generalize this slot to allow reference to the function.
names
:Object of class "character"
. The
names as noted are the class names separated by "#"
.
Class "namedList"
, directly.
Class "list"
, by class "namedList"
, distance 2.
Class "vector"
, by class "namedList"
, distance 3.
showMethods
, selectMethod
, Methods_Details
mm <- findMethods("Ops") findMethodSignatures(methods = mm)