| Line 1... |
Line 1... |
| 1 |
% File src/library/base/man/UseMethod.Rd
|
1 |
% File src/library/base/man/UseMethod.Rd
|
| 2 |
% Part of the R package, https://www.R-project.org
|
2 |
% Part of the R package, https://www.R-project.org
|
| 3 |
% Copyright 1995-2014 R Core Team
|
3 |
% Copyright 1995-2022 R Core Team
|
| 4 |
% Distributed under GPL 2 or later
|
4 |
% Distributed under GPL 2 or later
|
| 5 |
|
5 |
|
| 6 |
\name{UseMethod}
|
6 |
\name{UseMethod}
|
| 7 |
\title{Class Methods}
|
7 |
\title{Class Methods}
|
| 8 |
\alias{UseMethod}
|
8 |
\alias{UseMethod}
|
| Line 33... |
Line 33... |
| 33 |
\details{
|
33 |
\details{
|
| 34 |
An \R object is a data object which has a \code{class}
|
34 |
An \R object is a data object which has a \code{class}
|
| 35 |
attribute (and this can be tested by \code{\link{is.object}}).
|
35 |
attribute (and this can be tested by \code{\link{is.object}}).
|
| 36 |
A class attribute is a character vector giving the names of
|
36 |
A class attribute is a character vector giving the names of
|
| 37 |
the classes from which the object \emph{inherits}.
|
37 |
the classes from which the object \emph{inherits}.
|
| - |
|
38 |
|
| 38 |
If the object does not have a class attribute, it has an implicit
|
39 |
If the object does not have a class attribute, it has an
|
| 39 |
class. Matrices and arrays have class \code{"matrix"}
|
40 |
\emph{implicit class}. Matrices and arrays have class \code{"matrix"}
|
| 40 |
or\code{"array"} followed by the class of the underlying vector.
|
41 |
or \code{"array"} followed by the class of the underlying vector.
|
| 41 |
Most vectors have class the result of \code{\link{mode}(x)}, except
|
42 |
Most vectors have class the result of \code{\link{mode}(x)}, except
|
| 42 |
that integer vectors have class \code{c("integer", "numeric")} and
|
43 |
that integer vectors have class \code{c("integer", "numeric")} and
|
| 43 |
real vectors have class \code{c("double", "numeric")}.
|
44 |
real vectors have class \code{c("double", "numeric")}.
|
| - |
|
45 |
Function \code{\link{.class2}(x)} (since \R 4.0.x) returns the full
|
| - |
|
46 |
implicit (or explicit) class vector of \code{x}.
|
| 44 |
|
47 |
|
| 45 |
When a function calling \code{UseMethod("fun")} is applied to an
|
48 |
When a function calling \code{UseMethod("fun")} is applied to an
|
| 46 |
object with class attribute \code{c("first", "second")}, the system
|
49 |
object with class vector \code{c("first", "second")}, the system
|
| 47 |
searches for a function called \code{fun.first} and, if it finds it,
|
50 |
searches for a function called \code{fun.first} and, if it finds it,
|
| 48 |
applies it to the object. If no such function is found a function
|
51 |
applies it to the object. If no such function is found a function
|
| 49 |
called \code{fun.second} is tried. If no class name produces a
|
52 |
called \code{fun.second} is tried. If no class name produces a
|
| 50 |
suitable function, the function \code{fun.default} is used, if it
|
53 |
suitable function, the function \code{fun.default} is used, if it
|
| 51 |
exists, or an error results.
|
54 |
exists, or an error results.
|
| Line 169... |
Line 172... |
| 169 |
provided in the \pkg{methods} package.
|
172 |
provided in the \pkg{methods} package.
|
| 170 |
}
|
173 |
}
|
| 171 |
\seealso{
|
174 |
\seealso{
|
| 172 |
The draft \sQuote{R Language Definition}.
|
175 |
The draft \sQuote{R Language Definition}.
|
| 173 |
|
176 |
|
| 174 |
\code{\link{methods}}, \code{\link{class}},
|
177 |
\code{\link{methods}}, \code{\link{class}} incl \code{\link{.class2}()};
|
| 175 |
\code{\link{getS3method}}, \code{\link{is.object}}.
|
178 |
\code{\link{getS3method}}, \code{\link{is.object}}.
|
| 176 |
}
|
179 |
}
|
| 177 |
\references{
|
180 |
\references{
|
| 178 |
Chambers, J. M. (1992)
|
181 |
Chambers, J. M. (1992)
|
| 179 |
\emph{Classes and methods: object-oriented programming in S.}
|
182 |
\emph{Classes and methods: object-oriented programming in S.}
|