Rev 58549 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/methods/man/testInheritedMethods.Rd% Part of the R package, http://www.R-project.org% Copyright 2009-12 R Core Team% Distributed under GPL 2 or later\name{testInheritedMethods}\alias{testInheritedMethods}\alias{MethodSelectionReport-class}\alias{.Other-class}\title{Test for and Report about Selection of Inherited Methods}\description{A set of distinct inherited signatures is generated to testinheritance for all the methods of a specified generic function. Ifmethod selection is ambiguous for some of these, a summary of theambiguities is attached to the returned object. This test should beperformed by package authors \emph{before} releasing a package.}\usage{testInheritedMethods(f, signatures, test = TRUE, virtual = FALSE,groupMethods = TRUE, where = .GlobalEnv)}\arguments{\item{f}{a generic function or the character string name of one. By default,all currently defined subclasses of all the method signatures for thisgeneric will be examined. The other arguments are mainly options tomodify which inheritance patterns will be examined.}\item{signatures}{An optional set of subclass signatures to use instead of the relevantsubclasses computed by \code{testInheritedMethods}. See the Detailsfor how this is done. This argument might be supplied after a callwith \code{test = FALSE}, to test selection in batches.}\item{test}{optional flag to control whether method selection is actually tested.If \code{FALSE}, returns just the list of relevant signatures forsubclasses, without calling \code{\link{selectMethod}} for each signature.If there are a very large number of signatures, you may want to collect the full list and then test them in batches.}\item{virtual}{should virtual classes be included in the relevant subclasses.Normally not, since only the classes of actual arguments will triggerthe inheritance calculation in a call to the generic function.Including virtual classes may be useful if the class has no currentnon-virtual subclasses but you anticipate your users may define suchclasses in the future.}\item{groupMethods}{should methods for the group generic function be included?}\item{where}{the environment in which to look for class definitions. Nearlyalways, use the default global environment after attaching all thepackages with relevant methods and/or class definitions.}}\details{The following description applies when the optional arguments areomitted, the usual case.First, the defining signatures for all methods are computed by callsto \code{\link{findMethodSignatures}}.From these all the known non-virtual subclasses are found for eachclass that appears in the signature of some method.These subclasses are split into groups according to which class theyinherit from, and only one subclass from each group is retained (foreach argument in the generic signature).So if a method was defined with class \code{"vector"} for someargument, one actual vector class is chosen arbitrarily.The case of \code{"ANY"} is dealt with specially, since all classesextend it. A dummy, nonvirtual class, \code{".Other"}, is used tocorrespond to all classes that have no superclasses among those beingtested.All combinations of retained subclasses for thearguments in the generic signature are then computed.Each row of the resulting matrix is a signature to be tested by a callto \code{\link{selectMethod}}.To collect information on ambiguous selections,\code{testInheritedMethods} establishes a calling handler for thespecial signal \code{"ambiguousMethodSelection"}, by setting thecorresponding option.}\value{An object of class \code{"methodSelectionReport"}. The details ofthis class are currently subject to change. It has slots\code{"target"}, \code{"selected"}, \code{"candidates"}, and\code{"note"}, all referring to the ambiguous cases (and so of length0 if there were none). These slots are intended to be examined by theprogrammer to detect and preferably fix ambiguous method selections.The object contains in addition slots \code{"generic"}, the name ofthe generic function, and\code{"allSelections"}, giving the vector of labels for allthe signatures tested.}\references{Chambers, John M. (2008)\emph{Software for Data Analysis: Programming with R}Springer. (Section 10.6 for basics of method selection.)Chambers, John M. (2009)\emph{Class Inheritance in R}\url{http://stat.stanford.edu/~jmc4/classInheritance.pdf} (to besubmitted to the R Journal).}\examples{## if no other attached packages have methods for `+` or its group## generic functions, this returns a 16 by 2 matrix of selection## patterns (in R 2.9.0)testInheritedMethods("+")}\keyword{programming}\keyword{classes}\keyword{methods}