methods {utils}R Documentation

List Methods for S3 Generic Functions or Classes


List all available methods for a S3 and S4 generic function, or all methods for an S3 or S4 class.


   methods(generic.function, class, all.names = FALSE, dropPath = FALSE)
.S3methods(generic.function, class, envir = parent.frame(),
                                    all.names = FALSE, dropPath = FALSE)

## S3 method for class 'MethodsFunction'
format(x, byclass = attr(x, "byclass"), ...)
## S3 method for class 'MethodsFunction'
print(x, byclass = attr(x, "byclass"), ...)



a generic function, or a character string naming a generic function.


a symbol or character string naming a class: only used if generic.function is not supplied.


the environment in which to look for the definition of the generic function, when the generic function is passed as a character string.


a logical indicating if all object names are returned. When FALSE as by default, names beginning with a ‘⁠.⁠’ are omitted.


a logical indicating if the search() path, apart from .GlobalEnv and package:base (i.e., baseenv()), should be skipped when searching for method definitions. The default FALSE is back compatible and typically desired for print()ing, with or without asterisk; dropPath=TRUE has been hard coded in R 4.3.0 and is faster for non-small search() paths.


typically the result of methods(..), an R object of S3 class "MethodsFunction", see ‘Value’ below.


an optional logical allowing to override the "byclass" attribute determining how the result is printed, see ‘Details’.


potentially further arguments passed to and from methods; unused currently.


methods() finds S3 and S4 methods associated with either the generic.function or class argument. Methods found are those provided by all loaded namespaces via registration, see UseMethod; normally, this includes all packages on the current search() path. .S3methods() finds only S3 methods, .S4methods() finds only S4 methods.

When invoked with the generic.function argument, the "byclass" attribute (see Details) is FALSE, and the print method by default displays the signatures (full names) of S3 and S4 methods. S3 methods are printed by pasting the generic function and class together, separated by a ‘.’, as generic.class. The S3 method name is followed by an asterisk * if the method definition is not exported from the package namespace in which the method is defined. S4 method signatures are printed as generic,class-method; S4 allows for multiple dispatch, so there may be several classes in the signature generic,A,B-method.

When invoked with the class argument, "byclass" is TRUE, and the print method by default displays the names of the generic functions associated with the class, generic.

The source code for all functions is available. For S3 functions exported from the namespace, enter the method at the command line as generic.class. For S3 functions not exported from the namespace, see getAnywhere or getS3method. For S4 methods, see getMethod.

Help is available for each method, in addition to each generic. For interactive help, use the documentation shortcut ? with the name of the generic and tab completion, ?"generic<tab>" to select the method for which help is desired.

The S3 functions listed are those which are named like methods and may not actually be methods (known exceptions are discarded in the code).


An object of class "MethodsFunction", a character vector of method names with "byclass" and "info" attributes. The "byclass" attribute is a logical indicating if the results were obtained with argument class defined. The "info" attribute is a data frame with columns:


character vector of the names of the generic.


logical(), is the method “visible” to the user? When true, it typically is exported from the namespace of the package in which it is defined, and the package is attach()ed to the search() path.


logical(), true when the method is an S4 method.


a factor, the location or package name where the method was found.


The original methods function was written by Martin Maechler.


Chambers, J. M. (1992) Classes and methods: object-oriented programming in S. Appendix A of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.

See Also

S3Methods, class, getS3method.

For S4, getMethod, showMethods, Introduction or Methods_Details.


methods(class = "MethodsFunction") # format and print


methods(class = "aov")    # S3 class
## The same, with more details and more difficult to read:
print(methods(class = "aov"), byclass=FALSE)
methods("[[")             # uses C-internal dispatching
methods("$<-")            # replacement function
methods("+")              # binary operator
methods("Math")           # group generic
methods(axis)             # looks like a generic, but is not

mf <- methods(format)     # quite a few; ... the last few :
tail(cbind(meth = format(mf)))

if(require(Matrix, quietly = TRUE)) {
print(methods(class = "Matrix"))  # S4 class
m <- methods(dim)         # S3 and S4 methods
print(attr(m, "info"))    # more extensive information

## --> help(showMethods) for related examples

[Package utils version 4.4.0 Index]