| 42333 |
ripley |
1 |
% File src/library/utils/man/methods.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 67997 |
morgan |
3 |
% Copyright 1995-2015 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 27442 |
ripley |
6 |
\name{methods}
|
|
|
7 |
\title{List Methods for S3 Generic Functions or Classes}
|
| 67997 |
morgan |
8 |
\alias{.S3methods}
|
| 56186 |
murdoch |
9 |
\alias{methods}
|
| 27442 |
ripley |
10 |
\alias{print.MethodsFunction}
|
|
|
11 |
\description{
|
| 67997 |
morgan |
12 |
List all available methods for a S3 and S4 generic function, or all
|
|
|
13 |
methods for an S3 or S4 class.
|
| 27442 |
ripley |
14 |
}
|
|
|
15 |
\usage{
|
|
|
16 |
methods(generic.function, class)
|
| 68001 |
morgan |
17 |
.S3methods(generic.function, class, envir=parent.frame())
|
| 68162 |
maechler |
18 |
|
|
|
19 |
\S3method{print}{MethodsFunction}(x, byclass = attr(x, "byclass"), \dots)
|
| 27442 |
ripley |
20 |
}
|
|
|
21 |
\arguments{
|
|
|
22 |
\item{generic.function}{a generic function, or a character string naming a
|
|
|
23 |
generic function.}
|
|
|
24 |
\item{class}{a symbol or character string naming a class: only used if
|
|
|
25 |
\code{generic.function} is not supplied.}
|
| 68001 |
morgan |
26 |
\item{envir}{the environment in which to look for the definition of
|
|
|
27 |
the generic function, when the generic function is passed as a
|
|
|
28 |
character string.}
|
| 68162 |
maechler |
29 |
\item{x}{typically the result of \code{methods(..)}, an \R object of % S3
|
|
|
30 |
class \code{"MethodsFunction"}, see \sQuote{Value} below.}
|
|
|
31 |
\item{byclass}{an optional \code{\link{logical}} allowing to override
|
|
|
32 |
the \code{"byclass"} attribute determining how the result is
|
|
|
33 |
printed, see \sQuote{Details}.}
|
|
|
34 |
\item{\dots}{potentially further arguments passed to and from methods;
|
|
|
35 |
unused currently.}
|
| 27442 |
ripley |
36 |
}
|
| 67997 |
morgan |
37 |
|
|
|
38 |
\details{
|
|
|
39 |
\code{methods()} finds S3 and S4 methods associated with either the
|
|
|
40 |
\code{generic.function} or \code{class} argument. Methods are found in
|
|
|
41 |
all packages on the current \code{search()} path. \code{.S3methods()}
|
| 68087 |
morgan |
42 |
finds only S3 methods, \code{.S4methods()} finds only only S4 methods.
|
| 67997 |
morgan |
43 |
|
|
|
44 |
When invoked with the \code{generic.function} argument, the
|
| 68162 |
maechler |
45 |
\code{"byclass"} attribute (see Details) is \code{FALSE}, and the
|
|
|
46 |
\code{print} method by default displays the signatures (full names) of
|
|
|
47 |
S3 and S4 methods. S3 methods are printed by pasting the generic
|
|
|
48 |
function and class together, separated by a \sQuote{.}, as
|
| 67997 |
morgan |
49 |
\code{generic.class}. The S3 method name is followed by an asterisk
|
|
|
50 |
\code{*} if the method definition is not exported from the package
|
|
|
51 |
namespace in which the method is defined. S4 method signatures are
|
|
|
52 |
printed as \code{generic,class-method}; S4 allows for multiple
|
|
|
53 |
dispatch, so there may be several classes in the signature
|
|
|
54 |
\code{generic,A,B-method}.
|
|
|
55 |
|
| 68162 |
maechler |
56 |
When invoked with the \code{class} argument, \code{"byclass"} is
|
|
|
57 |
\code{TRUE}, and the \code{print} method by default displays the names
|
|
|
58 |
of the generic functions associated with the class, \code{generic}.
|
| 67997 |
morgan |
59 |
|
|
|
60 |
The source code for all functions is available. For S3 functions
|
|
|
61 |
exported from the namespace, enter the method at the command line as
|
|
|
62 |
\code{generic.class}. For S3 functions not exported from the
|
|
|
63 |
namespace, see \code{getAnywhere} or \code{getS3method}. For S4
|
|
|
64 |
methods, see \code{getMethod}.
|
|
|
65 |
|
|
|
66 |
Help is available for each method, in addition to each generic. For
|
|
|
67 |
interactive help, use the documentation shortcut \code{?} with the
|
|
|
68 |
name of the generic and tab completion, \code{?"generic<tab>"} to
|
|
|
69 |
select the method for which help is desired.
|
|
|
70 |
|
| 68087 |
morgan |
71 |
The S3 functions listed are those which \emph{are named like methods}
|
|
|
72 |
and may not actually be methods (known exceptions are discarded in the
|
|
|
73 |
code).
|
| 67997 |
morgan |
74 |
}
|
|
|
75 |
|
| 27442 |
ripley |
76 |
\value{
|
| 67997 |
morgan |
77 |
An object of class \code{"MethodsFunction"}, a character vector of
|
|
|
78 |
method names with \code{"byclass"} and \code{"info"} attributes. The
|
| 68162 |
maechler |
79 |
\code{"byclass"} attribute is a \code{\link{logical}} indicating if
|
|
|
80 |
the results were obtained with argument \code{class}
|
|
|
81 |
defined. The \code{"info"} attribute is a data frame with columns:
|
| 67997 |
morgan |
82 |
\describe{
|
| 68162 |
maechler |
83 |
\item{generic}{\code{\link{character}} vector of the names of the generic.}
|
|
|
84 |
\item{visible}{logical(), is the method exported from the namespace
|
| 67997 |
morgan |
85 |
of the package in which it is defined?}
|
|
|
86 |
\item{isS4}{logical(), true when the method is an S4 method.}
|
| 68162 |
maechler |
87 |
\item{from}{a \code{\link{factor}}, the location or package name
|
|
|
88 |
where the method was found.}
|
| 67997 |
morgan |
89 |
}
|
| 27442 |
ripley |
90 |
}
|
|
|
91 |
|
|
|
92 |
\note{
|
|
|
93 |
The original \code{methods} function was written by Martin Maechler.
|
|
|
94 |
}
|
| 67997 |
morgan |
95 |
|
| 27442 |
ripley |
96 |
\seealso{
|
| 49567 |
ripley |
97 |
\code{\link{S3Methods}}, \code{\link{class}}, \code{\link{getS3method}}.
|
| 44781 |
maechler |
98 |
|
| 67997 |
morgan |
99 |
For S4, \code{\link{getMethod}}, \code{\link{showMethods}},
|
| 71369 |
jmc |
100 |
\link[methods]{Introduction} or \code{\link{Methods_Details}}.
|
| 27442 |
ripley |
101 |
}
|
| 67997 |
morgan |
102 |
|
| 27442 |
ripley |
103 |
\references{
|
|
|
104 |
Chambers, J. M. (1992)
|
|
|
105 |
\emph{Classes and methods: object-oriented programming in S.}
|
|
|
106 |
Appendix A of \emph{Statistical Models in S}
|
| 47262 |
ripley |
107 |
eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
|
| 27442 |
ripley |
108 |
}
|
|
|
109 |
\examples{
|
| 41513 |
ripley |
110 |
require(stats)
|
|
|
111 |
|
| 27442 |
ripley |
112 |
methods(summary)
|
| 67997 |
morgan |
113 |
methods(class = "aov") # S3 class
|
| 68162 |
maechler |
114 |
## The same, with more details and more difficult to read:
|
|
|
115 |
print(methods(class = "aov"), byclass=FALSE)
|
| 67997 |
morgan |
116 |
methods("[[") # uses C-internal dispatching
|
| 35633 |
ripley |
117 |
methods("$")
|
| 67997 |
morgan |
118 |
methods("$<-") # replacement function
|
|
|
119 |
methods("+") # binary operator
|
|
|
120 |
methods("Math") # group generic
|
| 41502 |
ripley |
121 |
require(graphics)
|
| 67997 |
morgan |
122 |
methods("axis") # looks like a generic, but is not
|
|
|
123 |
|
| 68005 |
ripley |
124 |
if(require(Matrix)) {
|
|
|
125 |
print(methods(class = "Matrix")) # S4 class
|
|
|
126 |
m <- methods("dim") # S3 and S4 methods
|
|
|
127 |
print(m)
|
|
|
128 |
print(attr(m, "info")) # more extensive information
|
| 67997 |
morgan |
129 |
|
| 44781 |
maechler |
130 |
## --> help(showMethods) for related examples
|
|
|
131 |
}
|
| 68005 |
ripley |
132 |
}
|
| 27442 |
ripley |
133 |
\keyword{methods}
|