\HeaderA{RMethodUtils}{Method Utilities}{RMethodUtils}
\aliasA{.EmptyPrimitiveSkeletons}{RMethodUtils}{.EmptyPrimitiveSkeletons}
\aliasA{.saveImage}{RMethodUtils}{.saveImage}
\aliasA{.ShortPrimitiveSkeletons}{RMethodUtils}{.ShortPrimitiveSkeletons}
\aliasA{.valueClassTest}{RMethodUtils}{.valueClassTest}
\aliasA{addNextMethod}{RMethodUtils}{addNextMethod}
\aliasA{addNextMethod,MethodDefinition-method}{RMethodUtils}{addNextMethod,MethodDefinition.Rdash.method}
\aliasA{addNextMethod,MethodWithNext-method}{RMethodUtils}{addNextMethod,MethodWithNext.Rdash.method}
\aliasA{asMethodDefinition}{RMethodUtils}{asMethodDefinition}
\aliasA{assignMethodsMetaData}{RMethodUtils}{assignMethodsMetaData}
\aliasA{balanceMethodsList}{RMethodUtils}{balanceMethodsList}
\aliasA{cacheGenericsMetaData}{RMethodUtils}{cacheGenericsMetaData}
\aliasA{cacheMetaData}{RMethodUtils}{cacheMetaData}
\aliasA{conformMethod}{RMethodUtils}{conformMethod}
\aliasA{defaultDumpName}{RMethodUtils}{defaultDumpName}
\aliasA{derivedDefaultMethod-class}{RMethodUtils}{derivedDefaultMethod.Rdash.class}
\aliasA{doPrimitiveMethod}{RMethodUtils}{doPrimitiveMethod}
\aliasA{findUnique}{RMethodUtils}{findUnique}
\aliasA{generic.skeleton}{RMethodUtils}{generic.skeleton}
\aliasA{getGeneric}{RMethodUtils}{getGeneric}
\aliasA{getGroup}{RMethodUtils}{getGroup}
\aliasA{getGroupMembers}{RMethodUtils}{getGroupMembers}
\aliasA{getMethodsMetaData}{RMethodUtils}{getMethodsMetaData}
\aliasA{makeGeneric}{RMethodUtils}{makeGeneric}
\aliasA{makeStandardGeneric}{RMethodUtils}{makeStandardGeneric}
\aliasA{matchSignature}{RMethodUtils}{matchSignature}
\aliasA{MethodAddCoerce}{RMethodUtils}{MethodAddCoerce}
\aliasA{missingArg}{RMethodUtils}{missingArg}
\aliasA{nonstandardGeneric-class}{RMethodUtils}{nonstandardGeneric.Rdash.class}
\aliasA{nonstandardGenericFunction-class}{RMethodUtils}{nonstandardGenericFunction.Rdash.class}
\aliasA{nonstandardGroupGenericFunction-class}{RMethodUtils}{nonstandardGroupGenericFunction.Rdash.class}
\aliasA{OptionalFunction-class}{RMethodUtils}{OptionalFunction.Rdash.class}
\aliasA{PossibleMethod-class}{RMethodUtils}{PossibleMethod.Rdash.class}
\aliasA{rematchDefinition}{RMethodUtils}{rematchDefinition}
\aliasA{setPrimitiveMethods}{RMethodUtils}{setPrimitiveMethods}
\aliasA{sigToEnv}{RMethodUtils}{sigToEnv}
\aliasA{standardGeneric-class}{RMethodUtils}{standardGeneric.Rdash.class}
\aliasA{standardGenericWithTrace-class}{RMethodUtils}{standardGenericWithTrace.Rdash.class}
\aliasA{substituteFunctionArgs}{RMethodUtils}{substituteFunctionArgs}
\aliasA{unRematchDefinition}{RMethodUtils}{unRematchDefinition}
\keyword{internal}{RMethodUtils}
\begin{Description}\relax
Utility functions to support the definition and use of formal
methods.  Most of these functions will not normally be called directly
by the user.
\end{Description}
\begin{Usage}
\begin{verbatim}
getGeneric(f, mustFind=FALSE, where, package)

getGroup(fdef, recursive, where)
getGroupMembers(group, recursive = FALSE, character = TRUE)

getMethodsMetaData(f, where)
assignMethodsMetaData (f, value, fdef, where, deflt)

makeGeneric(f, fdef, fdefault =, group=list(), valueClass=character(),
            package =, signature = NULL, genericFunction = NULL,
            simpleInheritanceOnly = NULL)

makeStandardGeneric(f, fdef)

generic.skeleton(name, fdef, fdefault)

defaultDumpName(generic, signature)

doPrimitiveMethod(name, def, call= sys.call(sys.parent()),
                  ev = sys.frame(sys.parent(2)))

conformMethod(signature, mnames, fnames, f= , fdef, method)

matchSignature(signature, fun, where)

findUnique(what, message, where)

MethodAddCoerce(method, argName, thisClass, methodClass)

cacheMetaData(where, attach = TRUE, searchWhere =  as.environment(where),
              doCheck=TRUE)

cacheGenericsMetaData(f, fdef, attach = TRUE, where, package, methods)

setPrimitiveMethods(f, fdef, code, generic, mlist)

missingArg(symbol, envir = parent.frame(), eval)

balanceMethodsList(mlist, args, check = TRUE)

sigToEnv(signature, generic)

rematchDefinition(definition, generic, mnames, fnames, signature)
unRematchDefinition(definition)

asMethodDefinition(def, signature, sealed = FALSE, fdef)

addNextMethod(method, f, mlist, optional, envir)
\end{verbatim}
\end{Usage}
\begin{Section}{Summary of Functions}
\describe{

\item[\code{getGeneric}:] returns the definition of the function named \code{f} as a generic.

If no definition is found, throws an
error or returns \code{NULL} according to the value of
\code{mustFind}.  By default, searches in the top-level
environment (normally the global environment, but adjusted to
work correctly when package code is evaluated from the function
\code{\LinkA{library}{library}}).

Primitive functions are dealt with specially, since there is never
a formal generic definition for them.  The value returned is the
formal definition used for assigning methods to this primitive.
Not all primitives can have methods; if this one can't, then
\code{getGeneric} returns \code{NULL} or throws an error.


\item[\code{getGroup}:] returns the groups to which this generic belongs, searching from
environment \code{where} (the global environment normally by default).

If \code{recursive=TRUE}, also all the group(s) of these groups.


\item[\code{getGroupMembers}:] Return all the members of the group generic function named
\code{group}.
If \code{recursive} is \code{TRUE}, and some members are group
generics, includes their members as well.
If \code{character} is \code{TRUE}, returns just a character
vector of the names; otherwise returns a list, whose elements may
(or may not) include either names with a package attribute or
actual generic functions.

Note that members that are not defined as generic functions will
\emph{not} be included in the returned value.  To see the raw data,
use \code{getGeneric(group)@groupMembers}.


\item[\code{getMethodsMetaData},
\code{assignMethodsMetaData},
\code{mlistMetaName}:] Utilities to get
(\code{getMethodsMetaData}) and assign
(\code{assignMethodsMetaData}) the metadata object recording the
methods defined in a particular package, or to return the mangled
name for that object  (\code{mlistMetaName}).

The assign function should not be used directly.  The get
function may be useful if you want explicitly only the outcome of
the methods assigned in this package.  Otherwise, use
\code{\LinkA{getMethods}{getMethods}}.


\item[\code{matchSignature}:] Matches the signature object (a partially or completely named
subset of the signature arguments of the generic function object
\code{fun}), and return a vector of all the classes in the order
specified by \code{fun@signature}.  The classes not specified by
\code{signature} will be \code{"ANY"} in the value, but extra
trailing \code{"ANY"}'s are removed.  When the input signature is
empty, the returned signature is a single \code{"ANY"} matching
the first formal argument (so the returned value is always
non-empty).

Generates an error if any of the supplied signature names are
not legal; that is, not in the signature slot of the generic
function.

If argument \code{where} is supplied, a warning will be issued
if any of the classes does not have a formal definition visible
from \code{where}.


\item[\code{MethodAddCoerce}:] Possibly modify one or more methods to explicitly coerce this
argument to \code{methodClass}, the class for which the method is
explicitly defined.  Only modifies the method if an explicit
coerce is required to coerce from \code{thisClass} to
\code{methodClass}.


\item[\code{findUnique}:] Return the list of environments (or equivalent) having an object named
\code{what}, using environment \code{where} and its parent
environments.  If more than one is found, a warning message is
generated, using \code{message} to identify what was being
searched for, unless \code{message} is the empty string.


\item[\code{cacheMetaData},
\code{cacheGenericsMetaData},
\code{setPrimitiveMethods}:] Utilities for ensuring that the internal information about
class and method definitions is up to date.  Should normally be
called automatically whenever needed (for example, when a method
or class definition changes, or when a package is attached or
detached).  Required primarily because primitive functions are
dispatched in C code, rather than by the official model.

The \code{setPrimitiveMethods} function resets the caching
information for a particular primitive function.  Don't call it
directly.


\item[\code{missingArg}:] Returns \code{TRUE} if the symbol supplied is missing \emph{from
the call} corresponding to the environment supplied (by default,
environment of the call to \code{missingArg}).  If \code{eval} is
true, the argument is evaluated to get the name of the symbol to
test.  Note that \code{missingArg} is closer to the
\sQuote{Blue Book} sense of the \code{\LinkA{missing}{missing}} function,
not that of the current R base package implementation.  But beware
that it works reliably only if no assignment has yet been made to
the argument.  (For method dispatch this is fine, because
computations are done at the beginning of the call.)


\item[\code{balanceMethodsList}:] Called from \code{\LinkA{setMethod}{setMethod}} to ensure that all nodes in
the list have the same depth (i.e., the same number of levels of
arguments).  Balance is needed to ensure that all necessary
arguments are examined when inherited methods are being found and
added to the \code{allMethods} slot.  No actual recomputation is
needed usually except when a new method uses a longer signature
than has appeared before.

Balance requires that \emph{all} methods be added to the generic
via \code{setMethod} (how else could you do it?) or by the initial
\code{setGeneric} call converting the ordinary function.


\item[\code{sigToEnv}:] Turn the signature (a named vector of classes) into an environment
with the classes assigned to the names.  The environment is then
suitable for calling \code{\LinkA{MethodsListSelect}{MethodsListSelect}}, with
\code{evalArgs=FALSE}, to select a method corresponding to the
signature.  Usually not called directly: see
\code{\LinkA{selectMethod}{selectMethod}}.


\item[\code{.saveImage}:] Flag, used in dynamically initializing the methods package from
\code{.First.lib}


\item[\code{rematchDefinition},
\code{unRematchDefinition}:] If the specified method in a call to \code{\LinkA{setMethod}{setMethod}}
specializes the argument list (by replacing \dots), then
\code{rematchDefinition} constructs the actual method stored.
Using knowledge of how \code{rematchDefinition} works,
\code{unRematchDefinition} reverses the procedure; if given a
function or method definition that does not correspond to this
form, it just returns its argument.


\item[\code{asMethodDefinition}:] Turn a function definition into an object of class
\code{\LinkA{MethodDefinition}{MethodDefinition.Rdash.class}}, corresponding to the
given \code{signature} (by default generates a default method
with empty signature).  The definition is sealed according to
the \code{sealed} argument.


\item[\code{addNextMethod}:] A generic function that finds the next method for
the signature of the method definition \code{method}  and caches
that method in the method definition (promoting the class to
\code{"MethodWithNext"}.  Note that argument \code{mlist} is
obsolete and not used.


\item[\code{makeGeneric}:] Makes a generic function object corresponding to the given
function name, optional definition and optional default method.
Other arguments supply optional elements for the slots of class
\code{\LinkA{genericFunction}{genericFunction.Rdash.class}}.


\item[\code{makeStandardGeneric}:] a utility function that makes a valid function calling
\code{standardGeneric} for name \code{f}.  Works (more or less)
even if the actual definition, \code{fdef}, is not a proper
function, that is, it's a primitive or internal.


\item[\code{conformMethod}:] If the formal arguments, \code{mnames}, are not identical to the
formal arguments to the function, \code{fnames},
\code{conformMethod} determines whether the signature and the two
sets of arguments conform, and returns the signature, possibly
extended.  The function name, \code{f} is supplied for error
messages. The generic function, \code{fdef}, supplies the
generic signature  for matching purposes.

The method assignment conforms if either method and function have
identical formal argument lists.  It can also conform if the
method omits some of the formal arguments of the function but: (1)
the non-omitted arguments are a subset of the function arguments,
appearing in the same order; (2) there are no arguments to the
method that are not arguments to the function;  (3) the omitted
formal arguments do not appear as explicit classes in the
signature; and (4) the omitted arguments are not used as local
names or function names in the body of the method.


\item[\code{defaultDumpName}:] the default name to be used for dumping a method.



\item[\code{doPrimitiveMethod}:] do a primitive call to builtin function \code{name} the definition
and call provided, and carried out in the environment \code{ev}.

A call to \code{doPrimitiveMethod} is used when the actual method
is a .Primitive.  (Because primitives don't behave correctly as
ordinary functions, not having either formal arguments nor a
function body).


}
\end{Section}
\begin{SeeAlso}\relax
\code{\LinkA{setGeneric}{setGeneric}}, \code{\LinkA{setClass}{setClass}},
\code{\LinkA{showMethods}{showMethods}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
getGroup("exp")
getGroup("==", recursive = TRUE)

getGroupMembers("Arith")
getGroupMembers("Math")
getGroupMembers("Ops") # -> its sub groups
\end{ExampleCode}
\end{Examples}

