| 42333 |
ripley |
1 |
% File src/library/methods/man/showMethods.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 71228 |
maechler |
3 |
% Copyright 1995-2016 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 17211 |
jmc |
6 |
\name{showMethods}
|
| 56186 |
murdoch |
7 |
\alias{showMethods}
|
| 67997 |
morgan |
8 |
\alias{.S4methods}
|
|
|
9 |
\title{Show all the methods for the specified function(s) or class}
|
| 17211 |
jmc |
10 |
\description{
|
|
|
11 |
Show a summary of the methods for one or more generic functions,
|
|
|
12 |
possibly restricted to those involving specified classes.
|
|
|
13 |
}
|
|
|
14 |
\usage{
|
| 30912 |
ripley |
15 |
showMethods(f = character(), where = topenv(parent.frame()),
|
| 44243 |
ripley |
16 |
classes = NULL, includeDefs = FALSE,
|
|
|
17 |
inherited = !includeDefs,
|
| 51202 |
maechler |
18 |
showEmpty, printTo = stdout(), fdef)
|
| 67997 |
morgan |
19 |
.S4methods(generic.function, class)
|
| 17211 |
jmc |
20 |
}
|
|
|
21 |
\arguments{
|
| 26530 |
maechler |
22 |
\item{f}{one or more function names. If omitted, all functions
|
| 49771 |
jmc |
23 |
will be shown that match the other arguments.
|
| 61433 |
ripley |
24 |
|
| 49771 |
jmc |
25 |
The argument can also be an expression that evaluates to a single
|
|
|
26 |
generic function, in which
|
|
|
27 |
case argument \code{fdef} is ignored. Providing an expression for
|
|
|
28 |
the function allows examination of hidden or anonymous functions;
|
|
|
29 |
see the example for \code{isDiagonal()}.}
|
| 46419 |
ripley |
30 |
\item{where}{Where to find the generic function, if not supplied as an
|
|
|
31 |
argument. When \code{f} is missing, or length 0, this also
|
| 44805 |
jmc |
32 |
determines which generic functions to examine. If \code{where} is
|
| 39312 |
maechler |
33 |
supplied, only the generic functions returned by
|
|
|
34 |
\code{getGenerics(where)} are eligible for printing. If
|
|
|
35 |
\code{where} is also missing, all the cached generic functions are
|
|
|
36 |
considered.}
|
| 46419 |
ripley |
37 |
\item{classes}{If argument \code{classes} is supplied, it is a vector
|
| 19029 |
hornik |
38 |
of class names that restricts the displayed results to those methods
|
| 46419 |
ripley |
39 |
whose signatures include one or more of those classes.}
|
|
|
40 |
\item{includeDefs}{If \code{includeDefs} is \code{TRUE}, include the
|
|
|
41 |
definitions of the individual methods in the printout.}
|
| 42703 |
maechler |
42 |
\item{inherited}{logical indicating if methods that have been found by
|
|
|
43 |
inheritance, so far in the session, will be included and marked as
|
|
|
44 |
inherited. Note that an inherited method will not usually appear
|
| 46419 |
ripley |
45 |
until it has been used in this session. See
|
|
|
46 |
\code{\link{selectMethod}} if you want to know what method would be
|
| 26530 |
maechler |
47 |
dispatched for particular classes of arguments.}
|
| 39257 |
jmc |
48 |
\item{showEmpty}{logical indicating whether methods with no defined
|
| 39312 |
maechler |
49 |
methods matching the other criteria should be shown at all. By
|
|
|
50 |
default, \code{TRUE} if and only if argument \code{f} is not
|
|
|
51 |
missing.}
|
| 46419 |
ripley |
52 |
\item{printTo}{The connection on which the information will be
|
|
|
53 |
shown; by default, on standard output.}
|
|
|
54 |
\item{fdef}{Optionally, the generic function definition to use; if
|
|
|
55 |
missing, one is found, looking in \code{where} if that is specified.
|
|
|
56 |
See also comment in \sQuote{Details}.}
|
| 67997 |
morgan |
57 |
\item{generic.function, class}{See \code{methods}.}
|
| 17211 |
jmc |
58 |
}
|
|
|
59 |
\details{
|
| 67997 |
morgan |
60 |
See \code{methods} for a description of \code{.S4methods}.
|
|
|
61 |
|
| 39257 |
jmc |
62 |
The name and package of the generic are followed by the list of
|
|
|
63 |
signatures for which methods are currently defined, according to the
|
|
|
64 |
criteria determined by the various arguments. Note that the package
|
|
|
65 |
refers to the source of the generic function. Individual methods
|
|
|
66 |
for that generic can come from other packages as well.
|
| 44805 |
jmc |
67 |
|
| 46419 |
ripley |
68 |
When more than one generic function is involved, either as specified or
|
|
|
69 |
because \code{f} was missing, the functions are found and
|
|
|
70 |
\code{showMethods} is recalled for each, including the generic as the
|
|
|
71 |
argument \code{fdef}. In complicated situations, this can avoid some
|
|
|
72 |
anomalous results.
|
| 17211 |
jmc |
73 |
}
|
|
|
74 |
\value{
|
|
|
75 |
If \code{printTo} is \code{FALSE}, the character vector that would
|
| 19029 |
hornik |
76 |
have been printed is returned; otherwise the value is the connection
|
| 39257 |
jmc |
77 |
or filename, via \code{\link{invisible}}.
|
| 17211 |
jmc |
78 |
}
|
|
|
79 |
\references{
|
| 88585 |
hornik |
80 |
\bibshow{R:Chambers:2008}
|
|
|
81 |
(For the R version.)
|
| 17211 |
jmc |
82 |
|
| 88585 |
hornik |
83 |
\bibshow{R:Chambers:1998}
|
|
|
84 |
(For the original S4 version.)
|
| 17211 |
jmc |
85 |
}
|
| 19029 |
hornik |
86 |
\seealso{
|
|
|
87 |
\code{\link{setMethod}}, and \code{\link{GenericFunctions}}
|
| 26530 |
maechler |
88 |
for other tools involving methods;
|
| 21829 |
jmc |
89 |
\code{\link{selectMethod}} will show you the method dispatched for a
|
|
|
90 |
particular function and signature of classes for the arguments.
|
| 67997 |
morgan |
91 |
|
|
|
92 |
\code{\link{methods}} provides method discovery tools for light-weight
|
|
|
93 |
interactive use.
|
| 19029 |
hornik |
94 |
}
|
| 17211 |
jmc |
95 |
\examples{
|
| 41508 |
ripley |
96 |
require(graphics)
|
| 26000 |
ripley |
97 |
\dontshow{
|
| 71228 |
maechler |
98 |
setClass("track", slots = c(x="numeric", y="numeric"))
|
| 33606 |
maechler |
99 |
## First, with only one object as argument:
|
|
|
100 |
setMethod("plot", signature(x="track", y="missing"),
|
|
|
101 |
function(x, y, ...) plot(slot(x, "x"), slot(x, "y"), ...))
|
|
|
102 |
## Second, plot the data from the track on the y-axis against anything
|
|
|
103 |
## as the x data.
|
|
|
104 |
setMethod("plot", signature(y = "track"),
|
|
|
105 |
function(x, y, ...) plot(x, slot(y, "y"), ...))
|
|
|
106 |
setMethod("plot", "track",
|
|
|
107 |
function(x, y, ...) plot(slot(x, "y"), y, ...))
|
| 17454 |
jmc |
108 |
}
|
| 33606 |
maechler |
109 |
## Assuming the methods for plot
|
|
|
110 |
## are set up as in the example of help(setMethod),
|
|
|
111 |
## print (without definitions) the methods that involve class "track":
|
| 17376 |
jmc |
112 |
showMethods("plot", classes = "track")
|
| 17454 |
jmc |
113 |
\dontrun{
|
| 46945 |
murdoch |
114 |
# Function "plot":
|
|
|
115 |
# x = ANY, y = track
|
|
|
116 |
# x = track, y = missing
|
|
|
117 |
# x = track, y = ANY
|
| 34902 |
maechler |
118 |
|
| 49771 |
jmc |
119 |
require("Matrix")
|
| 44788 |
ripley |
120 |
showMethods("\%*\%")# many!
|
| 44781 |
maechler |
121 |
methods(class = "Matrix")# nothing
|
|
|
122 |
showMethods(class = "Matrix")# everything
|
| 49771 |
jmc |
123 |
showMethods(Matrix:::isDiagonal) # a non-exported generic
|
| 44781 |
maechler |
124 |
}%end{dontrun}
|
|
|
125 |
|
| 66580 |
maechler |
126 |
%% An example of showing methods from a loaded,
|
|
|
127 |
%% but not attached namespace.
|
|
|
128 |
if(no4 <- is.na(match("stats4", loadedNamespaces())))
|
|
|
129 |
loadNamespace("stats4")
|
|
|
130 |
showMethods(classes = "mle") # -> a method for show()
|
|
|
131 |
if(no4) unloadNamespace("stats4")
|
| 17454 |
jmc |
132 |
}
|
| 17211 |
jmc |
133 |
\keyword{methods}
|