Rev 70405 | Rev 86513 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/methods/man/RMethodUtils.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2015 R Core Team% Distributed under GPL 2 or later\name{RMethodUtils}\title{Method Utilities}%% FIXME: undocumented utilities (Sep. 23/02)\alias{asMethodDefinition}\alias{standardGeneric-class}\alias{standardGenericWithTrace-class}\alias{nonstandardGeneric-class}\alias{nonstandardGenericFunction-class}\alias{nonstandardGroupGenericFunction-class}\alias{OptionalFunction-class}\alias{PossibleMethod-class}\alias{optionalMethod-class}\alias{derivedDefaultMethod-class}\alias{internalDispatchMethod-class}%%\alias{substituteFunctionArgs}\alias{makeGeneric}\alias{makeStandardGeneric}\alias{generic.skeleton}\alias{defaultDumpName}\alias{doPrimitiveMethod}\alias{conformMethod}\alias{getGeneric}\alias{getGroup}\alias{getGroupMembers}\alias{getMethodsMetaData}\alias{assignMethodsMetaData}\alias{matchSignature}\alias{findUnique}\alias{MethodAddCoerce}\alias{.saveImage}\alias{cacheMetaData}\alias{cacheGenericsMetaData}\alias{setPrimitiveMethods}\alias{missingArg}\alias{balanceMethodsList}\alias{sigToEnv}\alias{rematchDefinition}\alias{isRematched}\alias{unRematchDefinition}\alias{addNextMethod,MethodDefinition-method}\alias{addNextMethod,MethodWithNext-method}\alias{addNextMethod}\alias{.valueClassTest}\alias{insertClassMethods}%% Not for the user to know about!\alias{.ShortPrimitiveSkeletons} %% used from C code\alias{.EmptyPrimitiveSkeletons}\description{Utility functions to support the definition and use of formalmethods. Most of these functions will not normally be called directlyby the user.}\usage{getGeneric(f, mustFind=FALSE, where, package)getGroup(fdef, recursive, where)getGroupMembers(group, recursive = FALSE, character = TRUE)getMethodsMetaData(f, where)assignMethodsMetaData (f, value, fdef, where)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)sigToEnv(signature, generic)rematchDefinition(definition, generic, mnames, fnames, signature)unRematchDefinition(definition)isRematched(definition)asMethodDefinition(def, signature, sealed = FALSE, fdef)addNextMethod(method, f, mlist, optional, envir)insertClassMethods(methods, Class, value, fieldNames, returnAll)balanceMethodsList(mlist, args, check = TRUE) # <- deprecated since R 3.2.0}\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 anerror or returns \code{NULL} according to the value of\code{mustFind}. By default, searches in the top-levelenvironment (normally the global environment, but adjusted towork correctly when package code is evaluated from the function\code{\link{library}}).Primitive functions are dealt with specially, since there is nevera formal generic definition for them. The value returned is theformal 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 fromenvironment \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 groupgenerics, includes their members as well.If \code{character} is \code{TRUE}, returns just a charactervector of the names; otherwise returns a list, whose elements may(or may not) include either names with a package attribute oractual 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 themethods defined in a particular package, or to return the mangledname for that object (\code{mlistMetaName}).The assign function should not be used directly. The getfunction may be useful if you want explicitly only the outcome ofthe methods assigned in this package. Otherwise, use\code{\link{getMethods}}.}\item{\code{matchSignature}:}{Matches the signature object (a partially or completely namedsubset of the signature arguments of the generic function object\code{fun}), and return a vector of all the classes in the orderspecified by \code{fun@signature}. The classes not specified by\code{signature} will be \code{"ANY"} in the value, but extratrailing \code{"ANY"}'s are removed. When the input signature isempty, the returned signature is a single \code{"ANY"} matchingthe first formal argument (so the returned value is alwaysnon-empty).Generates an error if any of the supplied signature names arenot legal; that is, not in the signature slot of the genericfunction.If argument \code{where} is supplied, a warning will be issuedif any of the classes does not have a formal definition visiblefrom \code{where}.}\item{\code{MethodAddCoerce}:}{Possibly modify one or more methods to explicitly coerce thisargument to \code{methodClass}, the class for which the method isexplicitly defined. Only modifies the method if an explicitcoerce 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 parentenvironments. If more than one is found, a warning message isgenerated, using \code{message} to identify what was beingsearched for, unless \code{message} is the empty string.}\item{\code{cacheMetaData},\code{cacheGenericsMetaData},\code{setPrimitiveMethods}:}{Utilities for ensuring that the internal information aboutclass and method definitions is up to date. Should normally becalled automatically whenever needed (for example, when a methodor class definition changes, or when a package is attached ordetached). Required primarily because primitive functions aredispatched in C code, rather than by the official model.The \code{setPrimitiveMethods} function resets the cachinginformation for a particular primitive function. Don't call itdirectly.}\item{\code{missingArg}:}{Returns \code{TRUE} if the symbol supplied is missing \emph{fromthe call} corresponding to the environment supplied (by default,environment of the call to \code{missingArg}). If \code{eval} istrue, the argument is evaluated to get the name of the symbol totest. Note that \code{missingArg} is closer to the\sQuote{Blue Book} sense of the \code{\link{missing}} function,not that of the current R base package implementation. But bewarethat it works reliably only if no assignment has yet been made tothe argument. (For method dispatch this is fine, becausecomputations are done at the beginning of the call.)}\item{\code{balanceMethodsList}:}{Used to be called from \code{setMethod()} and is \emph{deprecated}since \R version 3.2.0.%% Called from \code{\link{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 environmentwith the classes assigned to the names. The environment is thensuitable for calling \code{\link{MethodsListSelect}}, with\code{evalArgs=FALSE}, to select a method corresponding to thesignature. Usually not called directly: see\code{\link{selectMethod}}.}\item{\code{.saveImage}:}{Flag, used in dynamically initializing the methods package from\code{.onLoad}.}\item{\code{rematchDefinition},\code{unRematchDefinition},\code{isRematched}:}{If the specified method in a call to \code{\link{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 afunction or method definition that does not correspond to thisform, it just returns its argument. \code{isRematched} returns alogical value indicating whether rematching was used whenconstructing a given method.}\item{\code{asMethodDefinition}:}{Turn a function definition into an object of class\code{\linkS4class{MethodDefinition}}, corresponding to thegiven \code{signature} (by default generates a default methodwith empty signature). The definition is sealed according tothe \code{sealed} argument.}\item{\code{addNextMethod}:}{A generic function that finds the next method forthe signature of the method definition \code{method} and cachesthat method in the method definition (promoting the class to\code{"MethodWithNext"}). Note that argument \code{mlist} isobsolete and not used.}\item{\code{makeGeneric}:}{Makes a generic function object corresponding to the givenfunction name, optional definition and optional default method.Other arguments supply optional elements for the slots of class\code{\linkS4class{genericFunction}}.}\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 properfunction, that is, it's a primitive or internal.}\item{\code{conformMethod}:}{If the formal arguments, \code{mnames}, are not identical to theformal arguments to the function, \code{fnames},\code{conformMethod} determines whether the signature and the twosets of arguments conform, and returns the signature, possiblyextended. The function name, \code{f} is supplied for errormessages. The generic function, \code{fdef}, supplies thegeneric signature for matching purposes.The method assignment conforms if method and generic function haveidentical formal argument lists. It can also conform if themethod 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 themethod that are not arguments to the function; and (3) the omittedformal arguments do not appear as explicit classes in thesignature. A future extension hopes to test also that theomitted arguments are not assumed by being used as locally assignednames 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 definitionand call provided, and carried out in the environment \code{ev}.A call to \code{doPrimitiveMethod} is used when the actual methodis a .Primitive. (Because primitives don't behave correctly asordinary functions, not having either formal arguments nor afunction body).}}}\seealso{\code{\link{setGeneric}}, \code{\link{setClass}},\code{\link{showMethods}}.}\examples{getGroup("exp")getGroup("==", recursive = TRUE)getGroupMembers("Arith")getGroupMembers("Math")getGroupMembers("Ops") # -> its sub groups}\keyword{internal}