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