Rev 19064 | Rev 19115 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{RMethodUtils}\alias{makeGeneric}\alias{makeStandardGeneric}\alias{getAllMethods}\alias{generic.skeleton}\alias{defaultDumpName}\alias{getAllMethods}\alias{setAllMethodsSlot}\alias{doPrimitiveMethod}\alias{conformMethod}\alias{getGeneric}\alias{getGroup}\alias{getGroupMembers}\alias{setGroupMembers}\alias{getMethodsMetaData}\alias{assignMethodsMetaData}\alias{matchSignature}\alias{mlistMetaName}\alias{assignToMethodMetaData}\alias{getFromMethodMetaData}\alias{removeMethodsObject}\alias{findUnique}\alias{removeFromMethodMetaData}\alias{MethodAddCoerce}\alias{is.primitive}\alias{.saveImage}\alias{cacheMetaData}\alias{cacheGenericsMetaData}\alias{setPrimitiveMethods}\alias{copyEnvironment}\alias{printNoClass}\alias{print.default}\alias{missingArg}\alias{balanceMethodsList}\alias{sigToEnv}\alias{rematchDefinition}\alias{unRematchDefinition}\alias{.valueClassTest}%% Not for the user to know about!\alias{.ShortPrimitiveSkeletons} %% used from C code\alias{.EmptyPrimitiveSkeletons}\alias{__MethodMetaData}\title{RMethodUtils}\description{Utility functions to support the definition and use of formalmethods. Most of these functions will not normally be called directlyby the user.}\usage{makeGeneric(f, fdef, keepMethods=TRUE, useAsDefault=NA,group=character(), valueClass=character())makeStandardGeneric(f, fdef)generic.skeleton(name, fdef, fdefault)defaultDumpName(generic, signature)getAllMethods(f, libs=search())setAllMethodsSlot(mlist)doPrimitiveMethod(name, def, call=sys.call(-1), ev=sys.frame(-2))conformMethod(signature, mnames, fnames)getGeneric(f, mustFind=FALSE)getGroup(fdef, recursive=FALSE)getGroupMembers(f, fdef = getGeneric(f))setGroupMembers(f, members, fdef = getGeneric(f))matchSignature(names, signature, fun)## manage method metadatagetFromMethodMetaData(name)assignToMethodMetaData(name, value)removeFromMethodMetaData(name)removeMethodsObject(f, where)findUnique(what, doFind, message)MethodAddCoerce(method, argName, thisClass, methodClass)is.primitive(fdef)copyEnvironment(object, exceptions)cacheMetaData(envir, attach = TRUE)cacheGenericsMetaData(generics, attach = TRUE, envir)setPrimitiveMethods(f, fdef, code, generic, mlist)printNoClass(x, digits, quote, na.print, print.gap, right, ...)print.default(x, ...)missingArg(symbol, envir = parent.frame())balanceMethodsList(mlist, args, check = TRUE)sigToEnv(signature)rematchDefinition(definition, generic, mnames, fnames)unRematchDefinition(definition)}\section{Summary of Functions}{\describe{\item{\code{makeGeneric}:}{Makes a generic function object corresponding to the givenfunction name and optional definition.}\item{\code{makeStandardGeneric}:}{a utility function that makes a valid function callingstandardGeneric for name f. Works (more or less) even if theactual definition, fdef, is not a proper function, that is, it's aprimitive 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 method assignment conforms if either method and 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.}\item{\code{defaultDumpName}:}{the default name to be used for dumping a method.}\item{\code{getAllMethods}:}{a generic function (with methods) representing the merge of allthe versions of \code{f} on the specified packages (anything onthe current search path by default).If the generic \code{f} has a group generic, methods for thisgroup generic (and further generations of group generics, if any)are also merged.The merging rule is as follows: each generic is merged acrosspackages, and the group generics are then merged, finally addingthe directly defined methods of \code{f}.The effect of the merging rule is that any method directly definedfor \code{f} on any included package overrides a method for thesame signature defined for the group generic; similarly for thegroup generic and its group, if any, etc.For \code{f} or for a specific group generic, methods override inthe order of the packages being searched. A method for aparticular signature on a particular package overrides any methodsfor the same signature on packages later on in the list ofpackages being searched.The slot "allMethods" of the merged methods list is set to a copyof the methods slot; this is the slot where inherited methods arestored.}\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).}\item{\code{getGeneric}:}{return the definition of the function named f as a generic.If there is no definition in the current search list, throws anerror or returns NULL according to the value of mustFind.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}:}{return the groups to which this generic belongs.If \code{recursive=TRUE}, also all the group(s) of these groups.}\item{\code{getGroupMembers}, \code{setGroupMembers}:}{Get or set the known members of the group generic function \code{f}.}\item{\code{matchSignature}}{Matches the signature object (a partially or completely namedsubset of the arguments of \code{fun}), and return a vector of allthe classes in the order specified by \code{names}. The classesnot specified by `signature' will be \code{"ANY"} in the value,but extra trailing \code{"ANY"}'s are removed. When the inputsignature is empty, the returned signature is a single\code{"ANY"} matching the first formal argument (so the returnedvalue is always non-empty).The formal arguments of \code{fun} must agree with \code{names}(usually the formal arguments of the generic function) as well,and \code{matchSignature} checks this.}\item{\code{getMethodsMetaData}, \code{assignMethodsMetaData},\code{mlistMetaName}:}{utilities to manage methods list objects in a particular environment.Not to be called directly.}\item{\code{getFromMethodMetaData, assignToMethodMetaData,removeFromMethodMetaData}}{Functions to manage the session metadata for methods. Don'tcall these directly.}\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{is.primitive}}{Is this object a primitive function (either a builtin or special)?}\item{\code{removeMethodsObject}:}{remove the metadata object containing methods for \code{f}.}\item{\code{findUnique}:}{Find the first position on the search list containing object\code{what}; if more than one is found, a warning message isgenerated, using \code{message} to identify what was beingsearched for.If \code{doFind} is supplied, it's the version of \code{find} usedto do the search (e.g., \code{findFunction}.}\item{\code{cacheMetaData, cacheGenericsMetaData,setPrimitiveMethods}:}{Utilities for ensuring that the session-scope 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.The \code{environment} must be one of the environments on thecurrent search list; note in particular that even on detaching(\code{attach=FALSE}), the environment will normally still be onthe search list.The \code{setPrimitiveMethods} function resets the cachinginformation for a particular primitive function. Don't call itdirectly.}\item{\code{printNoClass},\code{print.default}: }{\code{printNoClass} is equivalent to the version of\code{print.default} in the base package. The methods packageoverrides the latter function to provide meaningful printing forformally defined classes, and \code{printNoClass} is used to getthe original default printing.}\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 ``blue-book''sense of the \code{\link{missing}} function, not that of thecurrent R base package implementation. But beware that it worksreliably only if no assignment has yet been made to the argument.(For method dispatch this is fine, because computations are doneat the begining of the call.)}\item{\code{balanceMethodsList}: }{Called from \code{\link{setMethod}} to ensure that all nodes inthe list have the same depth (i.e., the same number of levels ofarguments). Balance is needed to ensure that all necessaryarguments are examined when inherited methods are being found andadded to the \code{allMethods} slot. No actual recomputation isneeded usually except when a new method uses a longer signaturethan has appeared before.Balance requires that \emph{all} methods be added to the genericvia \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 themethods package from \code{.First.lib}}}\item{\code{rematchDefinition}, \code{unRematchDefinition}:}{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 a function or method definition thatdoes not correspond to this form, it just returns its argument.}}\keyword{internal}