| Line 4... |
Line 4... |
| 4 |
\title{ Create and Save a Method }
|
4 |
\title{ Create and Save a Method }
|
| 5 |
\description{
|
5 |
\description{
|
| 6 |
Create and save a formal method for a given function and list of classes.
|
6 |
Create and save a formal method for a given function and list of classes.
|
| 7 |
}
|
7 |
}
|
| 8 |
\usage{
|
8 |
\usage{
|
| 9 |
setMethod(f, signature=character(), definition, where=1, valueClass,
|
9 |
setMethod(f, signature=character(), definition, where= topenv(parent.frame()),
|
| 10 |
sealed = FALSE)
|
10 |
valueClass = NULL, sealed = FALSE)
|
| 11 |
|
11 |
|
| 12 |
removeMethod(f, signature, where)
|
12 |
removeMethod(f, signature, where)
|
| 13 |
}
|
13 |
}
|
| 14 |
\arguments{
|
14 |
\arguments{
|
| 15 |
\item{f}{ The character-string name of the generic function. }
|
15 |
\item{f}{ The character-string name of the generic function. }
|
| Line 19... |
Line 19... |
| 19 |
the first name corresponds to the first formal argument, the
|
19 |
the first name corresponds to the first formal argument, the
|
| 20 |
next to the second formal argument, etc.}
|
20 |
next to the second formal argument, etc.}
|
| 21 |
\item{definition}{ A function definition, which will become the method
|
21 |
\item{definition}{ A function definition, which will become the method
|
| 22 |
called when the arguments in a call to \code{f} match the
|
22 |
called when the arguments in a call to \code{f} match the
|
| 23 |
classes in \code{signature}, directly or through inheritance. }
|
23 |
classes in \code{signature}, directly or through inheritance. }
|
| 24 |
\item{where}{ The database in which to store the definition of the
|
24 |
\item{where}{the database in which to store the definition of the
|
| 25 |
method; by default, the current global environment.
|
25 |
method; % FIXME: by default, the ... environment.
|
| 26 |
|
26 |
|
| 27 |
For \code{removeMethod}, the default is the location of the (first)
|
27 |
For \code{removeMethod}, the default is the location of the (first)
|
| 28 |
instance of the method for this signature.}
|
28 |
instance of the method for this signature.}
|
| 29 |
\item{valueClass}{ If supplied, this argument asserts that the
|
29 |
\item{valueClass}{ If supplied, this argument asserts that the
|
| 30 |
method will return a value of this class. (At present this
|
30 |
method will return a value of this class. (At present this
|
| Line 91... |
Line 91... |
| 91 |
arguments, then the method may have extra formal arguments, which
|
91 |
arguments, then the method may have extra formal arguments, which
|
| 92 |
will be matched from the arguments matching \dots in the call to
|
92 |
will be matched from the arguments matching \dots in the call to
|
| 93 |
\code{f}. (What actually happens is that a local function is
|
93 |
\code{f}. (What actually happens is that a local function is
|
| 94 |
created inside the method, with its formal arguments, and the method
|
94 |
created inside the method, with its formal arguments, and the method
|
| 95 |
is re-defined to call that local function.)
|
95 |
is re-defined to call that local function.)
|
| 96 |
|
96 |
|
| 97 |
Method dispatch tries to match the class of the actual arguments in a
|
97 |
Method dispatch tries to match the class of the actual arguments in a
|
| 98 |
call to the available methods collected for \code{f}. Roughly, for
|
98 |
call to the available methods collected for \code{f}. Roughly, for
|
| 99 |
each formal argument in turn, we look for the best match (the exact
|
99 |
each formal argument in turn, we look for the best match (the exact
|
| 100 |
same class or the nearest element in the value of
|
100 |
same class or the nearest element in the value of
|
| 101 |
\code{\link{extends}} for that class) for which there is any
|
101 |
\code{\link{extends}} for that class) for which there is any
|
| Line 112... |
Line 112... |
| 112 |
While the programming interface for the \pkg{methods} package follows
|
112 |
While the programming interface for the \pkg{methods} package follows
|
| 113 |
the reference, the R software is an original implementation, so
|
113 |
the reference, the R software is an original implementation, so
|
| 114 |
details in the reference that reflect the S4 implementation may appear
|
114 |
details in the reference that reflect the S4 implementation may appear
|
| 115 |
differently in R. Also, there are extensions to the programming
|
115 |
differently in R. Also, there are extensions to the programming
|
| 116 |
interface developed more recently than the reference. For a
|
116 |
interface developed more recently than the reference. For a
|
| 117 |
discussion of details and ongoing development, see the web page
|
117 |
discussion of details and ongoing development, see the web page
|
| 118 |
\url{http://developer.r-project.org/methodsPackage.html} and the
|
118 |
\url{http://developer.r-project.org/methodsPackage.html} and the
|
| 119 |
pointers from that page.
|
119 |
pointers from that page.
|
| 120 |
}
|
120 |
}
|
| 121 |
\examples{
|
121 |
\examples{
|
| 122 |
\dontshow{ require(modreg)
|
122 |
\dontshow{ require(modreg)
|