Rev 7324 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{methods}\title{Class Methods}\usage{UseMethod(generic, object )NextMethod(generic, object, \dots)methods(generic.function, class)}\alias{UseMethod}\alias{NextMethod}\alias{methods}\description{\R possesses a simple generic function mechanism which can be used foran object-oriented style of programming. Method despatch takes placebased on the class of the first argument to the generic function or onthe object supplied as an argument to \code{UseMethod} or \code{NextMethod}.}\details{An \R ``object'' is a data object which has a \code{class} attribute.A class attribute is a vector of character strings giving the names ofthe classes which the object ``inherits'' from. When a genericfunction \code{fun} is applied to an object with class attribute\code{c("first", "second")}, the system searches for a function called\code{fun.first} and, if it finds it, applied it to the object. If nosuch function is found a function called \code{fun.second} is tried.If no class name produces a suitable function, the function\code{fun.default} is used.\code{methods} can be used to find out about the methods for aparticular generic function or class. See the examples below fordetails.Now for some obscure details that need to appear somewhere. Thesecomments will be slightly different than those in Appendix A of theWhite S Book. \code{UseMethod} creates a ``new'' function call witharguments matched as they came in to the generic. Any local variablesdefined before the call to \code{UseMethod} are retained (!?). Anystatements after the call to \code{UseMethod} will not be evaluated as\code{UseMethod} does not return.\code{NextMethod} invokes the next method (determined by theclass). It does this by creating a special call frame for thatmethod. The arguments will be the same in number, order and name asthose to the current method but their values will be promises toevaluate their name in the current method and environment. Anyarguments matched to \code{\dots} are handled specially. They arepassed on as the promise that was supplied as an argument to thecurrent environment. (S does this differently!) If they have beenevaluated in the current (or a previous environment) they remainevaluated.}\note{The \code{methods} function was written by Martin Maechler.}\seealso{\code{\link{class}}}\examples{methods(summary)methods(print)methods(class = data.frame)methods("[")#- does not list the C-internal ones...}\keyword{methods}