| Line 56... |
Line 56... |
| 56 |
be objects from these classes, they do not have the internal
|
56 |
be objects from these classes, they do not have the internal
|
| 57 |
structure of either an S3 or S4 class object. In particular, they
|
57 |
structure of either an S3 or S4 class object. In particular, they
|
| 58 |
have no \code{"class"} attribute and are not recognized as objects
|
58 |
have no \code{"class"} attribute and are not recognized as objects
|
| 59 |
with classes (that is, both \code{\link{is.object}} and
|
59 |
with classes (that is, both \code{\link{is.object}} and
|
| 60 |
\code{\link{isS4}} will return \code{FALSE} for such objects).
|
60 |
\code{\link{isS4}} will return \code{FALSE} for such objects).
|
| - |
|
61 |
However, methods (both S4 and S3) can be defined for these
|
| - |
|
62 |
pseudo-classes and new classes (both S4 and S3) can inherit from them.
|
| 61 |
|
63 |
|
| 62 |
That the objects still behave as if they came from the corresponding
|
64 |
That the objects still behave as if they came from the corresponding
|
| 63 |
class (most of the time, anyway) results from special code
|
65 |
class (most of the time, anyway) results from special code
|
| 64 |
recognizing such objects being built into the base code of \R.
|
66 |
recognizing such objects being built into the base code of \R.
|
| 65 |
For most purposes, treating the classes in the usual way will work,
|
67 |
For most purposes, treating the classes in the usual way will work,
|
| Line 69... |
Line 71... |
| 69 |
to \code{\link{setGeneric}} to create an S4 class that is a subclass
|
71 |
to \code{\link{setGeneric}} to create an S4 class that is a subclass
|
| 70 |
of \code{"matrix"}. There is no guarantee that everything will work
|
72 |
of \code{"matrix"}. There is no guarantee that everything will work
|
| 71 |
perfectly, but a number of classes have been written in this form
|
73 |
perfectly, but a number of classes have been written in this form
|
| 72 |
successfully.
|
74 |
successfully.
|
| 73 |
|
75 |
|
| - |
|
76 |
Note that a class containing \code{"matrix"} or \code{"array"} will
|
| - |
|
77 |
have a \code{.Data} slot with that class. This is the only use of
|
| - |
|
78 |
\code{.Data} other than as a pseudo-class indicating the type of the
|
| - |
|
79 |
object. In this case the type of the object will be the type of the
|
| - |
|
80 |
contained matrix or array. See \code{\link{Classes}} for a general
|
| - |
|
81 |
discussion.
|
| - |
|
82 |
|
| 74 |
The class \code{"ts"} is basically an S3 class
|
83 |
The class \code{"ts"} is basically an S3 class
|
| 75 |
that has been registered with S4, using the
|
84 |
that has been registered with S4, using the
|
| 76 |
\code{\link{setOldClass}} mechanism. Versions of \R through 2.7.0
|
85 |
\code{\link{setOldClass}} mechanism. Versions of \R through 2.7.0
|
| 77 |
treated this class as a pure S4 class, which was in principal a good
|
86 |
treated this class as a pure S4 class, which was in principal a good
|
| 78 |
idea, but in practice did not allow subclasses to be defined and had
|
87 |
idea, but in practice did not allow subclasses to be defined and had
|
| Line 81... |
Line 90... |
| 81 |
implementation does not allow the slot to be temporarily
|
90 |
implementation does not allow the slot to be temporarily
|
| 82 |
inconsistent with the length of the data. Also, the S4 class
|
91 |
inconsistent with the length of the data. Also, the S4 class
|
| 83 |
prevented the correct specification of the S3 inheritance for class
|
92 |
prevented the correct specification of the S3 inheritance for class
|
| 84 |
\code{"mts"}.)
|
93 |
\code{"mts"}.)
|
| 85 |
|
94 |
|
| 86 |
The current behavior (beginning with version 2.8.0 of \R) registers
|
95 |
Time-series objects, in contrast to matrices and arrays, have a valid
|
| 87 |
\code{"ts"} as an S3 class, using an S4-style definition (see the
|
96 |
S3 class, \code{"ts"}, registered using an S4-style definition (see the
|
| 88 |
documentation for \code{\link{setOldClass}} in the examples section
|
97 |
documentation for \code{\link{setOldClass}} in the examples section
|
| 89 |
for an abbreviated listing of how this is done. The S3
|
98 |
for an abbreviated listing of how this is done. The S3
|
| 90 |
inheritance of \code{"mts"} in package \pkg{stats} is also
|
99 |
inheritance of \code{"mts"} in package \pkg{stats} is also
|
| 91 |
registered.
|
100 |
registered.
|
| 92 |
These classes, as well as \code{"matrix"} and \code{"array"} should
|
101 |
These classes, as well as \code{"matrix"} and \code{"array"} should
|
| 93 |
be valid in most examples as superclasses for new S4 class
|
102 |
be valid in most examples as superclasses for new S4 class
|
| 94 |
definitions.
|
103 |
definitions.
|
| 95 |
|
104 |
|
| - |
|
105 |
All of these classes have special S4 methods for
|
| - |
|
106 |
\code{\link{initialize}} that accept the same arguments as the basic
|
| - |
|
107 |
generator functions, \code{\link{matrix}},
|
| - |
|
108 |
\code{\link{array}}, and \code{\link{ts}}, in so far as possible.
|
| - |
|
109 |
The limitation is that a class that has more than one non-virtual
|
| - |
|
110 |
superclass must accept objects from that superclass in the call to
|
| 96 |
|
- |
|
| - |
|
111 |
\code{\link{new}}; therefore, a such a class (what is called a
|
| - |
|
112 |
\dQuote{mixin} in some languages) uses the default method for
|
| - |
|
113 |
\code{\link{initialize}}, with no special arguments.
|
| 97 |
|
114 |
|
| 98 |
}
|
115 |
}
|
| 99 |
\section{Extends}{
|
116 |
\section{Extends}{
|
| 100 |
The specific classes all extend class \code{"structure"}, directly, and
|
117 |
The specific classes all extend class \code{"structure"}, directly, and
|
| 101 |
class \code{"vector"}, by class \code{"structure"}.
|
118 |
class \code{"vector"}, by class \code{"structure"}.
|