Rev 15825 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{getMethod}\alias{getMethod}\alias{getMethods}\alias{selectMethod}\alias{MethodsListSelect}\title{ Get the Definition of a Method }\description{A call to \code{getMethod} or \code{selectMethod} returns the methodcorresponding a particular generic function and signature (setclasses for formal arguments); \code{selectMethod} makes use ofinheritance, while \code{getMethod} does not. The function\code{getMethods} returns \emph{all} the methods for the generic function.}\usage{getMethod(f, signature=character(), where=-1, optional=FALSE)selectMethod(f, signature, optional=False, mlist=getMethods(f))getMethods(f, where=-1)MethodsListSelect(f, ev, mustFind = TRUE, ...)}\arguments{\item{f}{ The character-string name of the generic function }\item{signature}{ The signature of classes to match to the arguments of \code{f}. The vector of stringsfor the classes can be named or not. If named, the names must match formalargument names of \code{f}. If not named, the signature is assumed to apply to thearguments of \code{f} in order.}\item{where}{ Where to look for the method. By default, looks inall the currently defined methods. }\item{optional}{ If the selection does not produce a unique result,an error is generated, unless this argument is \code{TRUE}. Inthat case, the value returned is either a \code{MethodsList}object, if more than one method matches this signature, or\code{NULL} if no method matches.}\item{mlist}{In \code{selectMethod}, the \code{MethodsList} objectcan be explicitly supplied. (Unlikely to be used, except in therecursive call that finds matches to more than one argument.)}\item{ev}{The environment in which argument evaluations are done in\code{MethodsListSelect}. Currently must be supplied, but shouldusually be \code{sys.frame(sys.parent())} when calling the function explicitlyfor debugging purposes.}}\details{The functions \code{getMethod} and \code{selectMethod} usuallydiffer only in that the latter includes class inheritance in itssearch, and the former does not. For example, if class\code{"trackCurve"} has been defined to extend class \code{"track"},then at any stage of selection, if the signature wants class\code{"trackCurve"}, and the methods list has a \code{"track"}element but no \code{"trackCurve"} element, then \code{selectMethod}will pick that element, but \code{getMethod} will return\code{NULL}.The other differences between the two functions have to do withoptions on where to look: \code{getMethod} takes an environment ordatabase argument, \code{selectMethod} takes a \code{MethodsList}object.When \code{selectMethod} is called with a signature having more thanone argument, it does selection recursively. Look at the source forthe function for the precise definition, but the effect is roughlyas follows. An element of the \code{MethodsList} object is selectedaccording to the first element of the signature (an exact match tothe corresponding class name, an inherited match, or the default(\code{"ANY"}) element. The result may be a function, a\code{MethodsList} object, or \code{NULL} (no match). In the secondcase, if there are more elements in the signature,\code{selectMethod} drops the first element of the signature, andcalls itself recursively, with that object as the \code{mlist}argument.The function \code{MethodsListSelect} returns the method selected bythe evaluator for the specified function, being called from thesupplied environment. This is usually, but not always, the same asthat returned by \code{selectMethod} given the equivalent set ofclasses (i.e., the classes of the arguments used in defining methodsfor this function). The differences come because inheritancerelations can be conditional, and \code{selectMethod} does not havethat information, since it uses classes rather than actual objectsfrom those classes.Normally you won't call \code{MethodsListSelect} directly, but it ispossible to use it for debugging purposes (only for distinctlyadvanced users!).Note that the statement that \code{MethodsListSelect} corresponds to theselection done by the evaluator is a fact, not an assertion, in thesense that the evaluator code constructs and executes a call to\code{selectMethod} when it does not already have a cached methodfor this generic function and signature. (The value returned isstored by the evaluator so that the search is not required next time.)}\value{The call to \code{selectMethod} or \code{getMethod} returns afunction object, the selected method, if a unique selection exists.Otherwise an error is thrown if \code{optional} is \code{FALSE}. If\code{optional} is \code{TRUE}, the value returned is \code{NULL} ifno method matched, or a \code{MethodsList} object if multiplemethods matched.The call to \code{getMethods} returns the \code{MethodsList} objectcontaining all the methods requested. If there are none,\code{NULL} is returned: \code{getMethods} does not generate anerror in this case.}\references{The web page \url{http://www.omegahat.org/RSMethods/index.html} is the primary documentation.The functions in this package implement a facility for classes andmethods as described in\emph{Programming with Data}, (John M. Chambers, Springer, 1998). See this bookfor further details and examples.}\author{John Chambers}\examples{}\keyword{programming}\keyword{classes}\keyword{methods}