Rev 46128 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/methods/man/MethodsList.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2007 R Core Development Team% Distributed under GPL 2 or later\name{MethodsList}\alias{MethodsList}\alias{makeMethodsList}\alias{SignatureMethod}\alias{insertMethod}\alias{inheritedSubMethodLists}\alias{showMlist}\alias{print.MethodsList}\alias{emptyMethodsList}\alias{insertMethodInEmptyList}\alias{listFromMlist}\alias{linearizeMlist}\alias{finalDefaultMethod}\alias{mergeMethods}\alias{loadMethod}\alias{loadMethod-methods}\alias{loadMethod,ANY-method}\alias{loadMethod,MethodDefinition-method}\alias{loadMethod,MethodWithNext-method}\alias{MethodsListSelect}\title{MethodsList Objects}\description{These functions create and manipulate \code{MethodsList} objects, theobjects formerly used in R to store methods for dispatch. Use ofthese objects is no longer required, and while not yet formallydeprecated, will rarely be a good idea. Where methods dispatch isto be studied, see \code{\link{selectMethod}}. For computationsthat iterate over methods or over method signatures, see\code{\link{findMethods}}, which returns a linearized methods listto hold method definitions, usually more convenient for iterationthan the recursive \code{MethodsList} objects.}\usage{MethodsList(.ArgName, ...)makeMethodsList(object, level=1)SignatureMethod(names, signature, definition)insertMethod(mlist, signature, args, def, cacheOnly)inheritedSubMethodLists(object, thisClass, mlist, ev)showMlist(mlist, includeDefs = TRUE, inherited = TRUE,classes, useArgNames, printTo = stdout() )\method{print}{MethodsList}(x, ...)listFromMlist(mlist, prefix = list(), sigs. = TRUE, methods. = TRUE)linearizeMlist(mlist, inherited = TRUE)finalDefaultMethod(mlist, fname = "NULL")mergeMethods(m1, m2, genericLabel)loadMethod(method, fname, envir)MethodsListSelect(f, env, mlist, fEnv, finalDefault, evalArgs,useInherited, fdef, resetAllowed)}\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{"methods"}, but \code{cacheOnly=TRUE} insertsit into the \code{"allMethods"} slot (used for dispatch but not saved).}\item{\code{inheritedSubMethodLists}:}{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 corresponding definitions will be printed;otherwise, only the signatures.}\item{\code{listFromMlist}:}{Undo the recursive nature of the methods list, making a list of\code{list(sigs,methods)} of function definitions, i.e. ofmatching signatures and methods.\code{prefix} is the partial signature (a named list of classes)to be prepended to the signatures in this object. If \code{sigs.}or \code{methods.} are \code{FALSE}, the resulting part of thereturn value will be empty.A utility function used to iterate over all the individual methodsin the object, it calls itself recursively.}\item{\code{linearizeMlist}:}{Undo the recursive nature of the methods list, making a list offunction definitions, with the names of the list being thecorresponding signatures.Designed for printing; for looping over the methods, use the above\code{listFromMlist} instead.}\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 or no matching method is found, returns thefunction called \code{fname}, or \code{NULL} if there is no suchfunction.}\item{\code{mergeMethods}:}{Merges the methods in the second MethodsList object into thefirst, and returns the merged result. Called from\code{\link{getAllMethods}}. For a primitive function,\code{genericLabel} is supplied as the name of the generic.}\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. Class\code{MethodWithNext} has a method taking account of themechanism for storing the method to be used in a call to\code{\link{callNextMethod}}.Any methods defined for \code{loadMethod} must return the functiondefinition to be used for this call; typically, this is just the\code{method} argument.}\item{\code{MethodsListSelect}}{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. This search was used by the evaluator when methods listswere the metadata for methods dispatch. This function is now deprecated.}}}\note{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{Chambers, John M. (2008)\emph{Software for Data Analysis: Programming with R}Springer. (For the R version.)Chambers, John M. (1998)\emph{Programming with Data}Springer (For the original S4 version.)}\keyword{internal}