Methods are invoked (from a generic function) in one of three ways: from a call to UseMethod in an S-PLUS function; from internal code invoked through the .Internal interface; or from a call to NextMethod contained in another method. When a method is invoked, a special part of the S-PLUS evaluator, called the dispatcher is used.
When the dispatcher is invoked from a .Internal interface the matching mechanism is the same, with one addition and one exception. The addition is that methods can be defined and matched for the entire group of functions corresponding to a single internal interface. For example, all the functions using the Math interface can be matched for class factor by defining a method Math.factor. These functions include sin, abs and many others (see the reference for a table of all the groups and corresponding functions). The two other important groups are Ops (all operators) and Summary.
The exception is that for operators (arithmetic, comparison and logical) and [potentially] for functions with arbitrary numbers of arguments like c, the dispatcher looks for a single method that consistently matches all the relevant arguments. More precisely, all the arguments for which there is a non-default matching method must match to the same method. For example, suppose there is a method, Ops.factor, to handle all operators for class factor. Then x+y will use Ops.factor if Ops.factor is the matching method for both x and y, or if Ops.factor matches for one of x or y and there is no matching method for the other operand. The method code in Ops.factor is responsible for knowing which operands had matching methods and (because it is a group method) for knowing that "+" was the generic function. The special objects .Method and .Generic provide the needed information (see below).
Each group of generic functions consists of all of the functions that are .Internal calls to a specific routine. For example the Math group is internal calls to "do_math", Summary is calls to "do_summary", and the Ops group is calls to "do_op". Other less important groups (and the internal code that they call) are Extract ("S_extract"), Replace ("S_replace"), As ("As_vector"), and Is ("Is_vector"). There are a few other calls to .Internal that support generic functions, these are noted in the appropriate help files.
In addition to the arguments, the following special objects will exist in the frame of the method: