MethodsList {methods} | R Documentation |
MethodsList Objects
Description
These functions create and manipulate MethodsList
objects, the
objects used in R to store methods for dispatch. You should not call
any 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)
Details
Note that MethodsList
objects represent methods only in the R
implementation. You can use them to find or manipulate information about
methods, but avoid doing so if you want your code to port to S-Plus.
Details
MethodsList
:-
Create a MethodsList object out of the arguments.
Conceptually, this object is a named collection of methods to be dispatched when the (first) argument in a function call matches the class corresponding to one of the names. A final, unnamed element (i.e., with name
""
) corresponds to the default method.The elements can be either a function, or another MethodsList. In the second case, this list implies dispatching on the second argument to the function using that list, given a selection of this element on the first argument. Thus, method dispatching on an arbitrary number of arguments is defined.
MethodsList objects are used primarily to dispatch OOP-style methods and, in R, to emulate S4-style methods.
SignatureMethod
:-
construct a MethodsList object containing (only) this method, corresponding to the signature; i.e., such that
signature[[1]]
is the match for the first argument,signature[[2]]
for the second argument, and so on. The string"missing"
means a match for a missing argument, and"ANY"
means use this as the default setting at this level.The first argument is the argument names to be used for dispatch corresponding to the signatures.
insertMethod
:-
insert the definition
def
into the MethodsList object,mlist
, corresponding to the signature. By default, insert it in the slotwhich="methods"
, butcacheMethod
inserts it into thewhich="allMethods"
slot (used for dispatch but not saved). matchArg
:-
Utility function to match the object or the class (if the object is
NULL
) to the elements of a methods list. Used in finding inherited methods, and not meant to be called directly. showMlist
:-
Prints the contents of the MethodsList. If
includeDefs
the signatures and the corresonding definitions will be printed; otherwise, only the signatures.The function calls itself recursively:
prev
is the previously selected classes. listFromMlistForPrint
:-
Undo the recursive nature of the methods list, making a list of function defintions, with the names of the list being the corresponding signatures (designed for printing; for looping over the methods, use
listFromMlist
instead).The function calls itself recursively:
prev
is the previously selected classes. finalDefaultMethod
:-
The true default method for the methods list object
mlist
(the method that matches class"ANY"
for as many arguments as are used in methods matching for this generic function). Ifmlist
is null, returns the function calledfname
, orNULL
if there is no such function. mergeMethods
:-
Merges the methods in the second MethodsList object into the first, and returns the merged result. Called from
getAllMethods
. loadMethod
:-
Called, if necessary, just before a call to
method
is dispatched in the frameenvir
. The function exists so that methods can be defined for special classes of objects. Usually the point is to assign or modify information in the frame environment to be used evaluation. For example, the standard classMethodDefinition
has a method that stores the target and defined signatures in the environment.Any methods defined for
loadMethod
must return the function definition to be used for this call; typically, this is just themethod
argument.
Author(s)
John Chambers
References
The web page 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 Programming with Data (John M. Chambers, Springer, 1998). See this book for further details and examples.