Rev 68948 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/methods/man/implicitGeneric.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2007 R Core Team% Distributed under GPL 2 or later\name{implicitGeneric}\alias{implicitGeneric}\alias{setGenericImplicit}\alias{prohibitGeneric}\alias{registerImplicitGenerics}\alias{implicit generic}\title{Manage Implicit Versions of Generic Functions}\description{The implicit generic mechanism stores generic versions offunctionsin a table in a package. The package does not want the currentversion of the function to be a generic, however, and retains thenon-generic version.When a call to \code{\link{setMethod}} or\code{\link{setGeneric}} creates a generic version for one of thesefunctions, the object in the table is used.This mechanism is only needed if special arguments were used tocreate the generic; e.g., the \code{signature} or the \code{valueClass}options.Function \code{implicitGeneric()} returns the implicitgeneric version, \code{setGenericImplicit()} turns a generic implicit,\code{prohibitGeneric()} prevents your function from being madegeneric, and \code{registerImplicitGenerics()} saves a set of implicitgeneric definitions in the cached table of the current session.}\usage{implicitGeneric(name, where, generic)setGenericImplicit(name, where, restore = TRUE)prohibitGeneric(name, where)registerImplicitGenerics(what, where)}\arguments{\item{name}{ Character string name of the function.}\item{where}{ Package or environment in which to register the implicitgenerics. When using the functions from the top level of your ownpackage source, this argument should be omitted.}\item{generic}{ Obsolete, and likely to be deprecated.}\item{restore}{Should the non-generic version of the function berestored?.}\item{what}{Optional table ofthe implicit generics to register, but nearly always omitted, whenit defaults to a standard metadata name.}}\details{Multiple packages may define methods for the same function, to applyto classes defined in that package. Arithmetic and other operators,\code{plot()} and many other basic computations are typicalexamples. It's essential that all such packages write methods forthe \emph{same} definition of the generic function. So long as thatgeneric uses the default choice for signature and other parameters,nothing needs to be done.If the generic has special properties, these need to be ensured forall packages creating methods for it. The simplest solution is justto make the function generic in the package that originally ownedit. If for some reason the owner(s) of that package are unwillingto do this, the alternative is to define the correct generic,save it in a special table and restore the non-generic version bycalling \code{setGenericImplicit}.Note that the package containing the function can define methods for the implicit generic aswell; when the implicit generic is made a real generic, those methodswill be included.The usual reason for having anon-default implicit generic is to provide a non-default signature,and the usual reason for \emph{that} is to allow lazy evaluation ofsome arguments. All arguments in the signature of ageneric function must be evaluated at the time the function needs toselect a method.In the base function \code{with()} in the example below, evaluation of the argument\code{expr} must be delayed; therefore, it is excluded from the signature.If you want to completely prohibit anyone from turning your functioninto a generic, call \code{prohibitGeneric()}.Function \code{implicitGeneric()} returns the implicit genericversion of the named function. If there is no table of these or ifthis function is not in the table, the result of a simple call\code{setGeneric(name)} is returned.}\section{Implicit Generics for Base Functions}{Implicit generic versions exist for some functions in the packagessupplied in the distribution of \R itself. These are stored in the\sQuote{methods} package itself and will always be available.As emphasized repeatedly in the documentation,\code{\link{setGeneric}()} calls for a function in another packageshould never have non-default settings for arguments such as\code{signature}.The reasoning applies specially to functions in supplied packages,since methods for these are likely to exist in multiple packages.A call to \code{implicitGeneric()} will show the generic version.}\value{Function \code{implicitGeneric()} returns the implicit genericdefinition (and caches that definition the first time if it has toconstruct it).The other functions exist for their side effect and return nothinguseful.}\seealso{\code{\link{setGeneric}}}\examples{### How we would make the function with() into a generic:## Since the second argument, 'expr' is used literally, we want## with() to only have "data" in the signature.\dontrun{setGeneric("with", signature = "data")## Now we could predefine methods for "with" if we wanted to.## When ready, we store the generic as implicit, and restore theoriginalsetGenericImplicit("with")}implicitGeneric("with")# (This implicit generic is stored in the 'methods' package.)}\keyword{programming}\keyword{methods}