The R Project SVN R

Rev

Rev 59039 | Rev 67997 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/methods/man/showMethods.Rd
2
% Part of the R package, http://www.R-project.org
59039 ripley 3
% Copyright 1995-2007 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
17211 jmc 6
\name{showMethods}
56186 murdoch 7
\alias{showMethods}
39312 maechler 8
\title{Show all the methods for the specified function(s)}
17211 jmc 9
\description{
10
  Show a summary of the methods for one or more generic functions,
11
  possibly restricted to those involving specified classes.
12
}
13
\usage{
30912 ripley 14
showMethods(f = character(), where = topenv(parent.frame()),
44243 ripley 15
            classes = NULL, includeDefs = FALSE,
16
            inherited = !includeDefs,
51202 maechler 17
            showEmpty, printTo = stdout(), fdef)
17211 jmc 18
}
19
\arguments{
26530 maechler 20
  \item{f}{one or more function names.  If omitted, all functions
49771 jmc 21
    will be shown that match the other arguments.
61433 ripley 22
 
49771 jmc 23
    The argument can also be an expression that evaluates to a single
24
    generic function, in which
25
    case argument \code{fdef} is ignored.  Providing an expression for
26
    the function allows examination of hidden or anonymous functions;
27
    see the example for \code{isDiagonal()}.}
46419 ripley 28
  \item{where}{Where to find the generic function, if not supplied as an
29
    argument. When \code{f} is missing, or length 0, this also
44805 jmc 30
    determines which generic functions to examine.  If \code{where} is
39312 maechler 31
    supplied, only the generic functions returned by
32
    \code{getGenerics(where)} are eligible for printing.  If
33
    \code{where} is also missing, all the cached generic functions are
34
    considered.}
46419 ripley 35
  \item{classes}{If argument \code{classes} is supplied, it is a vector
19029 hornik 36
    of class names that restricts the displayed results to those methods
46419 ripley 37
    whose signatures include one or more of those classes.}
38
  \item{includeDefs}{If \code{includeDefs} is \code{TRUE}, include the
39
    definitions of the individual methods in the printout.}
42703 maechler 40
  \item{inherited}{logical indicating if methods that have been found by
41
    inheritance, so far in the session, will be included and marked as
42
    inherited.  Note that an inherited method will not usually appear
46419 ripley 43
    until it has been used in this session.  See
44
    \code{\link{selectMethod}} if you want to know what method would be
26530 maechler 45
    dispatched for particular classes of arguments.}
39257 jmc 46
  \item{showEmpty}{logical indicating whether methods with no defined
39312 maechler 47
    methods matching the other criteria should be shown at all.  By
48
    default, \code{TRUE} if and only if argument \code{f} is not
49
    missing.}
46419 ripley 50
  \item{printTo}{The connection on which the information will be
51
    shown; by default, on standard output.}
52
  \item{fdef}{Optionally, the generic function definition to use; if
53
    missing, one is found, looking in \code{where} if that is specified.
54
    See also comment in \sQuote{Details}.}
17211 jmc 55
}
56
\details{
39257 jmc 57
  The name and package of the generic are followed by the list of
58
  signatures for which methods are currently defined, according to the
59
  criteria determined by the various arguments.  Note that the package
60
  refers to the source of the generic function.  Individual methods
61
  for that generic can come from other packages as well.
44805 jmc 62
 
46419 ripley 63
  When more than one generic function is involved, either as specified or
64
  because \code{f} was missing, the functions are found and
65
  \code{showMethods} is recalled for each, including the generic as the
66
  argument \code{fdef}.  In complicated situations, this can avoid some
67
  anomalous results.
17211 jmc 68
}
69
\value{
70
  If \code{printTo} is \code{FALSE}, the character vector that would
19029 hornik 71
  have been printed is returned; otherwise the value is the connection
39257 jmc 72
  or filename, via \code{\link{invisible}}.
17211 jmc 73
}
74
\references{
46128 jmc 75
 Chambers, John M. (2008)
76
 \emph{Software for Data Analysis: Programming with R}
77
  Springer.  (For the R version.)
17211 jmc 78
 
46128 jmc 79
 Chambers, John M. (1998)
80
 \emph{Programming with Data}
81
 Springer (For the original S4 version.)
17211 jmc 82
}
19029 hornik 83
\seealso{
84
  \code{\link{setMethod}}, and \code{\link{GenericFunctions}}
26530 maechler 85
  for other tools involving methods;
21829 jmc 86
  \code{\link{selectMethod}} will show you the method dispatched for a
87
  particular function and signature of classes for the arguments.
19029 hornik 88
}
17211 jmc 89
\examples{
41508 ripley 90
require(graphics)
26000 ripley 91
\dontshow{
33606 maechler 92
 setClass("track",
93
          representation(x="numeric", y="numeric"))
94
 ## First, with only one object as argument:
95
 setMethod("plot", signature(x="track", y="missing"),
96
           function(x,  y, ...) plot(slot(x, "x"), slot(x, "y"), ...))
97
 ## Second, plot the data from the track on the y-axis against anything
98
 ## as the x data.
99
 setMethod("plot", signature(y = "track"),
100
           function(x, y, ...) plot(x, slot(y, "y"), ...))
101
 setMethod("plot", "track",
102
           function(x, y, ...) plot(slot(x, "y"), y,  ...))
17454 jmc 103
}
33606 maechler 104
## Assuming the methods for plot
105
## are set up as in the example of help(setMethod),
106
## print (without definitions) the methods that involve class "track":
17376 jmc 107
showMethods("plot", classes = "track")
17454 jmc 108
\dontrun{
46945 murdoch 109
# Function "plot":
110
# x = ANY, y = track
111
# x = track, y = missing
112
# x = track, y = ANY
34902 maechler 113
 
49771 jmc 114
require("Matrix")
44788 ripley 115
showMethods("\%*\%")# many!
44781 maechler 116
    methods(class = "Matrix")# nothing
117
showMethods(class = "Matrix")# everything
49771 jmc 118
showMethods(Matrix:::isDiagonal) # a non-exported generic
44781 maechler 119
}%end{dontrun}
120
 
39257 jmc 121
%% FIXME: This should be an example of showing methods from a loaded,
44781 maechler 122
%% but not attached namespace. Except it doesn't work.
123
%% Much simpler situation of attach()ing when needed:
34902 maechler 124
not.there <- !any("package:stats4" == search())
125
if(not.there) library(stats4)
41621 ripley 126
showMethods(classes = "mle")
34902 maechler 127
if(not.there) detach("package:stats4")
17454 jmc 128
}
17211 jmc 129
\keyword{methods}