The R Project SVN R

Rev

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