Rev 18994 | Blame | Last modification | View Log | Download | RSS feed
\name{MethodsList}\alias{MethodsList}\alias{makeMethodsList}\alias{SignatureMethod}\alias{insertMethod}\alias{matchArg}\alias{matchArgClass}\alias{showMlist}\alias{print.MethodsList}\alias{emptyMethodsList}\alias{insertMethodInEmptyList}\alias{listFromMlist}\alias{linearizeMlist}\alias{finalDefaultMethod}\alias{mergeMethods}\alias{loadMethod}\title{MethodsList Objects}\description{These functions create and manipulate \code{MethodsList} objects, theobjects used in R to store methods for dispatch. You should not callany of these functions from code that you want to port to S-Plus.Instead, use the functions described in the references.}\usage{MethodsList(.ArgName, ...)makeMethodsList(object, level=1)SignatureMethod(names, signature, definition)insertMethod(mlist, signature, args, def, whichMethods)matchArg(object, thisClass, mlist, ev)showMlist(mlist, includeDefs = TRUE, inherited = TRUE,classes, useArgNames, printTo = stdout() )print.MethodsList(x, ...)listFromMlist(mlist, prefix = list())linearizeMlist(mlist, inherited = TRUE)finalDefaultMethod(mlist, fname = "NULL")mergeMethods(m1, m2)loadMethod(method, fname, envir)}\section{Details}{\describe{\item{\code{MethodsList}:}{Create a MethodsList object out of the arguments.Conceptually, this object is a named collection of methods to bedispatched when the (first) argument in a function call matchesthe class corresponding to one of the names. A final, unnamedelement (i.e., with name \code{""}) corresponds to the defaultmethod.The elements can be either a function, or another MethodsList. Inthe second case, this list implies dispatching on the secondargument to the function using that list, given a selection ofthis element on the first argument. Thus, method dispatching onan arbitrary number of arguments is defined.MethodsList objects are used primarily to dispatch OOP-stylemethods and, in R, to emulate S4-style methods.}\item{\code{SignatureMethod}:}{construct a MethodsList object containing (only) this method,corresponding to the signature; i.e., such that\code{signature[[1]]} is the match for the first argument,\code{signature[[2]]} for the second argument, and so on. Thestring \code{"missing"} means a match for a missing argument, and\code{"ANY"} means use this as the default setting at this level.The first argument is the argument names to be used for dispatchcorresponding to the signatures.}\item{\code{insertMethod}:}{insert the definition \code{def} into the MethodsList object,\code{mlist}, corresponding to the signature. By default, insertit in the slot \code{which="methods"}, but\code{\link{cacheMethod}} inserts it into the\code{which="allMethods"} slot (used for dispatch but notsaved).}\item{\code{matchArg}:}{Utility function to match the object or the class (if the objectis \code{NULL}) to the elements of a methods list.Used in finding inherited methods, and not meant to be calleddirectly.}\item{\code{showMlist}:}{Prints the contents of the MethodsList. If \code{includeDefs} thesignatures and the corresonding definitions will be printed;otherwise, only the signatures.The function calls itself recursively: \code{prev} is thepreviously selected classes.}\item{\code{listFromMlistForPrint}:}{Undo the recursive nature of the methods list, making a list offunction defintions, with the names of the list being thecorresponding signatures (designed for printing; for looping overthe methods, use \code{\link{listFromMlist}} instead).The function calls itself recursively: \code{prev} is thepreviously selected classes.}\item{\code{finalDefaultMethod}:}{The true default method for the methods list object \code{mlist}(the method that matches class \code{"ANY"} for as many argumentsas are used in methods matching for this generic function). If\code{mlist} is null, returns the function called \code{fname}, or\code{NULL} if there is no such function.}\item{\code{mergeMethods}:}{Merges the methods in the second MethodsList object into thefirst, and returns the merged result. Called from\code{\link{getAllMethods}}.}\item{\code{loadMethod}:}{Called, if necessary, just before a call to \code{method} isdispatched in the frame \code{envir}. The function exists so thatmethods can be defined for special classes of objects. Usuallythe point is to assign or modify information in the frameenvironment to be used evaluation. For example, the standardclass \code{MethodDefinition} has a method that stores the targetand defined signatures in the environment.Any methods defined for \code{loadMethod} must return the functiondefinition to be used for this call; typically, this is just the\code{method} argument.}}}\details{Note that \code{MethodsList} objects represent methods only in the \Rimplementation. You can use them to find or manipulate information aboutmethods, but avoid doing so if you want your code to port to S-Plus.}\references{The web page \url{http://www.omegahat.org/RSMethods/index.html} is theprimary documentation.The functions in this package emulate the facility for classes andmethods described in \emph{Programming with Data} (John M. Chambers,Springer, 1998). See this book for further details and examples.}\author{John Chambers}\keyword{internal}