Blame | Last modification | View Log | Download | RSS feed
\name{methods}\title{Class Methods}\usage{UseMethod (name)NextMethod(name, object, ...)methods(generic.function, class)}\alias{UseMethod}\alias{NextMethod}\alias{methods}\description{R possesses a simple generic function mechanismwhich can be used for an object-oriented style of programming.Method despatch takes place based on the class of the first argumentto the generic function.An R ``object'' is a data object which has a \code{class} attribute.A class attribute is a vector of character strings giving thenames of the classes which the object ``inherits'' from.When a generic function \code{fun} is applied to an objectwith class attribute c("first","second"), the system searchesfor a function called \code{fun.first} and, if it finds it,applied it to the object. If no such function is founda function called \code{fun.second} is tried.If no class name produces a suitable function, the function\code{fun.default} is used.The function \code{class} prints the vector of names of classeswhich an object inherits from.Correspondingly, \code{class<-} sets the classeswhich an object inherits from.\code{unclass} returns (a copy of) its argumentwith its class information removed.\code{inherits} indicates whether its first argument inheritsfrom a class with name equal to its second argument.\code{methods} can be used to find out about the methodsfor a particular generic function or class.See the examples below for details.Now for some obscure details that need to appear somewhere.These comments will be slightly different than those in Appendix A ofthe White S Book. \code{UseMethod}creates a "new" function call with arguments matched as they came in tothe generic. Any local variables defined before the call to UseMethod areretained (!?). Any statements after the call to \code{UseMethod} willnot be evaluated as \code{UseMethod} does not return.\code{NextMethod} invokes the next method (determined by the class). Itdoes this by creating a special call frame for that method. The argumentswill be the same in number, order and name as those to the current methodbut their values will be promises to evaluate their name in the currentmethod and environment. Any arguments matched to \code{...} are handledspecially. They are passed on as the promise that was supplied as anargument to the current environment. (S does this differently!) If theyhave been evaluated in the current (or a previous environment) theyremain evaluated.}\note{The \code{methods} function was written by Martin Maechler.}\seealso{\code{\link{class}}}\examples{methods(summary)cat("methods(print):\n")print(methods(print))cat("methods(class = data.frame):\n")print(methods(class = data.frame))}