Rev 15514 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{Methods}\alias{isGeneric}\alias{removeGeneric}\alias{standardGeneric}\alias{dumpMethod}\alias{existsFunction}\alias{findFunction}\alias{dumpMethods}\alias{showMethods}\alias{removeMethods}\alias{signature}\alias{setReplaceMethod}\title{Defining Methods and Generic Functions}\usage{isGeneric(f, where = -1, fdef, getName = FALSE)removeGeneric(name, where=-1)standardGeneric(fname)dumpMethod(generic, signature=character(), file=defaultDumpName(generic, signature), where=-1, def=getMethod(generic, signature, where = where, optional = TRUE))existsFunction(name, generic = TRUE, where = find(name, mode ="function", numeric = TRUE))findFunction(name, generic=TRUE)dumpMethods(f, file="", signature=character(), methods, where=-1)signature(...)showMethods(f, where, classes, includeDefs=FALSE, inherited = TRUE)removeMethods(f, where)setReplaceMethod(f, ...)}\description{These are the functions that deal with formally defined methods.Brief documentation is provided below. See the references for anintroduction and for more details.\code{isGeneric}:Is there a function named \code{f}, and if so, is it a generic?\code{removeGeneric}:Remove the generic function of this name.\code{standardGeneric}:Dispatches a method from the current function call for the generic function \code{fname}.\code{getMethods}:The list of methods for the specified generic.\code{getMethod}:Return the function that is defined as the method for this generic function and signature(classes to be matched to the arguments of the generic function).\code{dumpMethod}:Dump the method for this generic function and signature.\code{existsFunction}:Is there a function of this name. If \code{generic==FALSE}, generic functions are not counted.\code{findFunction}:return all the elements of the search list on which a functiondefinition for \code{name} exists.\code{selectMethod}:Returns the method (a function) that R would use to evaluate a call to this generic,with arguments corresponding to the specified signature.f = the name of the generic functionsig = the signature of classes to match to the arguments of f.\code{dumpMethods}:Dump all the methods for this generic.\code{signature}:Returns a named list of classes to be matched to arguments of ageneric function.\code{showMethods}:Show all the methods for the specified function.If \code{where} is supplied, the definition from that database will be used; otherwise,the current definition is used (which will include inherited methods that have arisen sofar in the session).The argument \code{classes} is included for consistency with S-Plus, but currently ignored.Similarly, omitting \code{f} is not currently supported.\code{removeMethods}:removes all the methods defined for this generic function.\code{setReplaceMethod}:defines a method for \code{f}, used as a replacement function on theleft of an assignment, by calling \code{\link{setMethod}} for thecorresponding generic replacement function. The \code{...} argumentsare passed to \code{\link{setMethod}}.}\details{\code{setGeneric}:If there is already a non-generic function of this name, it will be usedto define the generic unless \code{def} is supplied, and the current function willbecome the default method for the generic.If \code{def} is supplied, this defines the generic function, and no default methodwill exist (often a good feature, if the function should only be available fora meaningful subset of all objects).Arguments \code{group} and \code{valueClass} are retained for consistency with S-Plus, butare currently not used.\code{isGeneric}:If the \code{fdef} argument is supplied, take this as the definition of thegeneric, and test whether it is really a generic, with \code{f} as the name ofthe generic. (This argument is not available in S-Plus.)\code{removeGeneric}:If \code{where} supplied, just remove the version on this element of the search list;otherwise, removes the first version encountered.\code{standardGeneric}:Generic functions should usually have a call to \code{standardGeneric} as their entirebody. They can, however, do any other computations as well.The usual \code{setGeneric} (directly or through calling\code{setMethod}) creates a function with a call to\code{standardGeneric}.\code{getMethods}:If the function is nota generic function, returns NULL.The \code{f} argument can be either the character string name of the genericor the object itselfThe \code{where} argument optionally says where to look for the function, if\code{f} is given as the name.\code{dumpMethod}:The resulting source file will recreate the method.\code{findFunction}:If \code{generic} is FALSE, ignore genericfunctions.\code{selectMethod}:The vector of stringsfor the classes can be named or not. If named, the names must match formalargument names of f. If not named, the signature is assumed to apply to thearguments of f in order.mustFind = If TRUE, an error results if there is no method (or no unique method)corresponding to this signature. Otherwise may return NULL or a MethodsListobject.\code{dumpMethods}:If \code{signature} is supplied only the methods matching this initial signatureare dumped. (This feature is not found in S-Plus: don't use it if you wantcompatibility.)\code{signature}:The advantageof using \code{signature} is to provide a check on which arguments you meant, as wellas clearer documentation in your method specification. In addition, \code{signature}checks that each of the elements is a single character string.\code{showMethods}:The output style is different from S-Plus in that it does not show the databasefrom which the definition comes, but can optionally include the method definitions,if \code{includeDefs == TRUE}.\code{removeMethods}:Returns \code{TRUE} if\code{f} was a generic function, \code{FALSE} (silently) otherwise.If there is a default method, the function will be re-assigned asa simple function with this definition; otherwise, it will be removed. Theassignment or removal can be controlled by optional argument \code{where}, whichdefaults to the first element of the search list having a function called \code{f}.}\references{The web page \url{http://www.omegahat.org/RSMethods/index.html} is the primary documentation.The functions in this package emulate the facility for classes and methods described in\emph{Programming with Data}, (John M. Chambers, Springer, 1998). See this bookfor further details and examples.}\author{John Chambers}\seealso{\code{\link{setGeneric}}, \code{\link{setClass}}}\keyword{programming}\keyword{classes}\keyword{methods}