| Line 54... |
Line 54... |
| 54 |
there is no class attribute, the implicit class is tried, then the
|
54 |
there is no class attribute, the implicit class is tried, then the
|
| 55 |
default method.
|
55 |
default method.
|
| 56 |
|
56 |
|
| 57 |
The function \code{class} prints the vector of names of classes an
|
57 |
The function \code{class} prints the vector of names of classes an
|
| 58 |
object inherits from. Correspondingly, \code{class<-} sets the
|
58 |
object inherits from. Correspondingly, \code{class<-} sets the
|
| 59 |
classes an object inherits from. Assigning a zero-length vector or
|
59 |
classes an object inherits from. Assigning \code{NULL} removes the
|
| 60 |
\code{NULL} removes the class attribute.
|
60 |
class attribute.
|
| 61 |
|
61 |
|
| 62 |
\code{unclass} returns (a copy of) its argument with its class
|
62 |
\code{unclass} returns (a copy of) its argument with its class
|
| 63 |
attribute removed. (It is not allowed for objects which cannot be
|
63 |
attribute removed. (It is not allowed for objects which cannot be
|
| 64 |
copied, namely environments and external pointers.)
|
64 |
copied, namely environments and external pointers.)
|
| 65 |
|
65 |
|
| Line 81... |
Line 81... |
| 81 |
\code{\link{UseMethod}} dispatches on the class as returned by
|
81 |
\code{\link{UseMethod}} dispatches on the class as returned by
|
| 82 |
\code{class} (with some interpolated classes: see the link) rather
|
82 |
\code{class} (with some interpolated classes: see the link) rather
|
| 83 |
than \code{oldClass}. \emph{However}, \link{group generic}s dispatch
|
83 |
than \code{oldClass}. \emph{However}, \link{group generic}s dispatch
|
| 84 |
on the \code{oldClass} for efficiency, and \link{internal generic}s
|
84 |
on the \code{oldClass} for efficiency, and \link{internal generic}s
|
| 85 |
only dispatch on objects for which \code{\link{is.object}} is true.
|
85 |
only dispatch on objects for which \code{\link{is.object}} is true.
|
| - |
|
86 |
|
| - |
|
87 |
In some versions of \R, assigning a zero-length vector with
|
| - |
|
88 |
\code{class} removes the class: in others it is an error (whereas it
|
| - |
|
89 |
works for \code{oldClass}. It is clearer to always assign \code{NULL}
|
| - |
|
90 |
to remove the class.
|
| 86 |
}
|
91 |
}
|
| 87 |
|
92 |
|
| 88 |
\section{Formal classes}{
|
93 |
\section{Formal classes}{
|
| 89 |
An additional mechanism of \emph{formal} classes, nicknamed
|
94 |
An additional mechanism of \emph{formal} classes, nicknamed
|
| 90 |
\dQuote{S4}, is available in
|
95 |
\dQuote{S4}, is available in package \pkg{methods} which is attached
|
| 91 |
packages \pkg{methods} which is attached by default. For objects
|
96 |
by default. For objects which have a formal class, its name is
|
| 92 |
which have a formal class, its name is returned by \code{class}
|
97 |
returned by \code{class} as a character vector of length one and
|
| 93 |
as a character vector of length one and method dispatch can happen on
|
98 |
method dispatch can happen on \emph{several} arguments, instead of
|
| 94 |
\emph{several} arguments, instead of only the first. However, S3 method selection
|
99 |
only the first. However, S3 method selection attempts to treat objects
|
| 95 |
attempts to treat objects from an S4 class as if they had the
|
100 |
from an S4 class as if they had the appropriate S3 class attribute, as
|
| 96 |
appropriate S3 class attribute, as does \code{inherits}. Therefore,
|
101 |
does \code{inherits}. Therefore, S3 methods can be defined for S4
|
| 97 |
S3 methods can be defined for S4 classes. See the \sQuote{\link{Classes}}
|
102 |
classes. See the \sQuote{\link{Classes}} and \sQuote{\link{Methods}}
|
| 98 |
and \sQuote{\link{Methods}} help pages for details.
|
103 |
help pages for details.
|
| 99 |
|
104 |
|
| 100 |
The replacement version of the function sets the class to the value
|
105 |
The replacement version of the function sets the class to the value
|
| 101 |
provided. For classes that have a formal definition, directly
|
106 |
provided. For classes that have a formal definition, directly
|
| 102 |
replacing the class this way is strongly deprecated. The expression
|
107 |
replacing the class this way is strongly deprecated. The expression
|
| 103 |
\code{\link{as}(object, value)} is the way to coerce an object to a
|
108 |
\code{\link{as}(object, value)} is the way to coerce an object to a
|