The R Project SVN R

Rev

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

Rev Author Line No. Line
42333 ripley 1
% File src/library/utils/man/methods.Rd
2
% Part of the R package, http://www.R-project.org
59039 ripley 3
% Copyright 1995-2007 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}
56186 murdoch 8
\alias{methods}
27442 ripley 9
\alias{print.MethodsFunction}
10
\description{
11
  List all available methods for an S3 generic function, or all
12
  methods for a class.
13
}
14
\usage{
15
methods(generic.function, class)
16
}
17
\arguments{
18
  \item{generic.function}{a generic function, or a character string naming a
19
    generic function.}
20
  \item{class}{a symbol or character string naming a class: only used if
21
    \code{generic.function} is not supplied.}
22
}
23
\value{
24
  An object of class \code{"MethodsFunction"}, a
25
  character vector of function names with an \code{"info"} attribute.
26
  There is a \code{print} method which marks with an asterisk any
27
  methods which are not visible: such functions can be examined by
28
  \code{\link{getS3method}} or \code{\link{getAnywhere}}.
29
 
30
  The \code{"info"} attribute is a data frame, currently with a
31
  logical column, \code{visible} and a factor column \code{from}
32
  (indicating where the methods were found).
33
}
34
\details{
35
  Function \code{methods} can be used to find out about the methods for
36
  a particular generic function or class.  The functions listed are those
37
  which \emph{are named like methods} and may not actually be methods
38
  (known exceptions are discarded in the code).  Note that the listed
39
  methods may not be user-visible objects, but often help will be
40
  available for them.
41
 
42
  If \code{class} is used, we check that a matching generic can be found
35633 ripley 43
  for each user-visible object named.  If \code{generic.function} is
44
  given, there is a warning if it appears not to be a generic function.
45
  (The check for being generic used can be fooled.)
27442 ripley 46
}
47
\note{
48
  This scheme is called \emph{S3} (S version 3).  For new projects,
49
  it is recommended to use the more flexible and robust \emph{S4} scheme
50
  provided in the \pkg{methods} package.  Functions can have both S3
30461 ripley 51
  and S4 methods, and function \code{\link{showMethods}} will
27442 ripley 52
  list the S4 methods (possibly none).
53
 
54
  The original \code{methods} function was written by Martin Maechler.
55
}
56
\seealso{
49567 ripley 57
  \code{\link{S3Methods}}, \code{\link{class}}, \code{\link{getS3method}}.
44781 maechler 58
 
49567 ripley 59
  For S4, \code{\link{showMethods}}, \code{\link{Methods}}.
27442 ripley 60
}
61
\references{
62
  Chambers, J. M. (1992)
63
  \emph{Classes and methods: object-oriented programming in S.}
64
  Appendix A of \emph{Statistical Models in S}
47262 ripley 65
  eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
27442 ripley 66
}
67
\examples{
41513 ripley 68
require(stats)
69
 
27442 ripley 70
methods(summary)
71
methods(class = "aov")
35633 ripley 72
methods("[[")    # uses C-internal dispatching
73
methods("$")
27442 ripley 74
methods("$<-")   # replacement function
75
methods("+")     # binary operator
76
methods("Math")  # group generic
41502 ripley 77
require(graphics)
35633 ripley 78
methods("axis")  # looks like it has methods, but not generic
44781 maechler 79
\dontrun{
80
methods(print)   # over 100
81
}
82
## --> help(showMethods) for related examples
83
}
27442 ripley 84
\keyword{methods}