Rev 19029 | Rev 19473 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{getMethod}\alias{getMethod}\alias{findMethod}\alias{getMethods}\alias{selectMethod}\alias{MethodsListSelect}\title{ Get the Definition of a Method }\description{A call to \code{getMethod} returns the method corresponding aparticular generic function and signature; a call to \code{findMethod}returns the vector of package names in which a matching method is found.The functions \code{MethodsListSelect} and \code{selectMethod} selectmethods using an environment in which arguments to the function havebeen assigned (they differ in the treatment of inheritance). Neitheris intended to be called directly, except perhaps in debugging. Thefunction \code{getMethods} returns \emph{all} the methods for thegeneric function.The function \code{findMethod} returns the package(s) in the searchlist (or in the packages specified by the \code{where} argument) thatcontain a method for this function and signature.}\usage{getMethod(f, signature=character(), where, optional=FALSE)findMethod(f, signature, where)getMethods(f, where=-1)MethodsListSelect(f, env, mlist, fEnv, finalDefault, evalArgs, useInherited)selectMethod(f, signature, optional=FALSE, useInherited, mlist=getMethods(f))}\arguments{\item{f}{ The character-string name of the generic function.In \code{getMethods} only, this argument may be a functiondefinition, in which case the special methods list object, if any,stored in the environment of the function is returned. (This usageis largely for internal purposes; you aren't likely to have such afunction definition for direct use.)}\item{signature}{ The signature of classes to match to the argumentsof \code{f}. The vector of strings for the classes should be named,and the names must match formal argument names of \code{f}. If notnamed, the signature is assumed to apply to the arguments of\code{f} in order, but note below for \code{selectMethod}.For \code{selectMethod}, the signature can optionally be anenvironment with classes assigned to the names of the correspondingarguments. If the signature is not an environment, it mustcurrently be named.}\item{where}{ The position or environment in which to look for the method: by default,anywhere inthe current search list.}\item{optional}{ If the selection does not produce a unique result,an error is generated, unless this argument is \code{TRUE}. In thatcase, the value returned is either a \code{MethodsList} object, ifmore than one method matches this signature, or \code{NULL} if nomethod 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{env}{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 functionexplicitly for debugging purposes.}\item{fEnv, finalDefault, evalArgs, useInherited}{ Internal-usearguments for the function's environment, the method to use asthe overall default, whether to evaluate arguments, and whicharguments should use inheritance.}}\details{A call to \code{getMethod} returns the method for a particularfunction and signature. As with other \code{get} functions,argument \code{where} controls where the function looks (by defaultanywhere in the search list) and argument \code{optional} controlswhether the function returns \code{NULL} or generates an error ifthe method is not found. The search for the method makes no use ofinheritance.The function \code{getMethods} returns all the methods for aparticular generic (in the form of a generic function with themethods information in its environment). The function is calledfrom the evaluator to merge method information, and is not intendedto be called directly.The function \code{MethodsListSelect} performs a full search(including all inheritance and group generic information: see the\link{Methods} documentation page for details on how this works).The call returns a possibly revised methods list object,incorporating any method found as part of the \code{allMethods}slot.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{MethodsListSelect} 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 nexttime.)The \code{selectMethod} function is similar to\code{MethodsListSelect} (and calls it) but differs in that itis intended to be used with control over which arguments are allowedto use inheritance. The restriction is needed to make sensiblemethod selection for coerce methods (the \code{\link{as}} function).}\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 theprimary documentation.The functions in this package implement a facility for classes andmethods as described in \emph{Programming with Data} (JohnM. Chambers, Springer, 1998). See this book for further details andexamples.}\author{John Chambers}\keyword{programming}\keyword{classes}\keyword{methods}