| Line 20... |
Line 20... |
| 20 |
\description{
|
20 |
\description{
|
| 21 |
Old-style (S3) classes may be registered as S4 classes (by calling
|
21 |
Old-style (S3) classes may be registered as S4 classes (by calling
|
| 22 |
\code{\link{setOldClass}}, and many have been. These classes can
|
22 |
\code{\link{setOldClass}}, and many have been. These classes can
|
| 23 |
then be contained in (that is, superclasses of) regular S4 classes, allowing formal methods
|
23 |
then be contained in (that is, superclasses of) regular S4 classes, allowing formal methods
|
| 24 |
and slots to be added to the S3 behavior. The function
|
24 |
and slots to be added to the S3 behavior. The function
|
| 25 |
\code{S3Part} extracts or replaces
|
25 |
\code{S3Part} extracts or replaces
|
| 26 |
the S3 part of such an object.
|
26 |
the S3 part of such an object.
|
| 27 |
\code{S3Class} extracts or
|
27 |
\code{S3Class} extracts or
|
| 28 |
replaces the S3-style class. \code{S3Class} also applies to object
|
28 |
replaces the S3-style class. \code{S3Class} also applies to object
|
| 29 |
from an S4 class with \code{S3methods=TRUE} in the call to \code{\link{setClass}}.
|
29 |
from an S4 class with \code{S3methods=TRUE} in the call to \code{\link{setClass}}.
|
| 30 |
|
30 |
|
| 31 |
See the details below.
|
31 |
See the details below.
|
| 32 |
Also discussed are S3 <-> S4 coercion; see the section
|
32 |
Also discussed are S3 <-> S4 coercion; see the section
|
| 33 |
\dQuote{S3 and S4 objects}
|
33 |
\dQuote{S3 and S4 objects}
|
| 34 |
}
|
34 |
}
|
| 35 |
\usage{
|
35 |
\usage{
|
| Line 108... |
Line 108... |
| 108 |
New S4 classes that extend (contain) such
|
108 |
New S4 classes that extend (contain) such
|
| 109 |
classes also have the same slot, and by default the prototype has
|
109 |
classes also have the same slot, and by default the prototype has
|
| 110 |
the value determined by the \code{contains=} argument to
|
110 |
the value determined by the \code{contains=} argument to
|
| 111 |
\code{\link{setClass}}.
|
111 |
\code{\link{setClass}}.
|
| 112 |
Individual objects from the S4 class may
|
112 |
Individual objects from the S4 class may
|
| 113 |
have
|
113 |
have
|
| 114 |
an S3 class corresponding to the value in the prototype or to an
|
114 |
an S3 class corresponding to the value in the prototype or to an
|
| 115 |
(S3) subclass of that value. See the examples below.
|
115 |
(S3) subclass of that value. See the examples below.
|
| 116 |
|
116 |
|
| 117 |
\code{S3Part()} with \code{strictS3 = TRUE} constructs the underlying S3 object by eliminating
|
117 |
\code{S3Part()} with \code{strictS3 = TRUE} constructs the underlying S3 object by eliminating
|
| 118 |
all the formally defined slots and turning off the S4 bit of the
|
118 |
all the formally defined slots and turning off the S4 bit of the
|
| Line 212... |
Line 212... |
| 212 |
the object to create an object from the S4 definition of
|
212 |
the object to create an object from the S4 definition of
|
| 213 |
\code{class(object)}. This is a general mechanism to create
|
213 |
\code{class(object)}. This is a general mechanism to create
|
| 214 |
partially defined version of S4 objects via S3 computations (not
|
214 |
partially defined version of S4 objects via S3 computations (not
|
| 215 |
much different from invoking \code{\link{new}} with corresponding
|
215 |
much different from invoking \code{\link{new}} with corresponding
|
| 216 |
arguments, but usable in this form even if the S4 object has an
|
216 |
arguments, but usable in this form even if the S4 object has an
|
| 217 |
initialize method with different arguments).
|
217 |
initialize method with different arguments).
|
| 218 |
}
|
218 |
}
|
| 219 |
|
219 |
|
| 220 |
\references{
|
220 |
\references{
|
| 221 |
Chambers, John M. (2008)
|
221 |
Chambers, John M. (2008)
|
| 222 |
\emph{Software for Data Analysis: Programming with R}
|
222 |
\emph{Software for Data Analysis: Programming with R}
|
| Line 267... |
Line 267... |
| 267 |
## S3Part() applied to classes with a data part (.Data slot)
|
267 |
## S3Part() applied to classes with a data part (.Data slot)
|
| 268 |
|
268 |
|
| 269 |
setClass("NumX", contains="numeric", representation(id="character"))
|
269 |
setClass("NumX", contains="numeric", representation(id="character"))
|
| 270 |
nn = new("NumX", 1:10, id="test")
|
270 |
nn = new("NumX", 1:10, id="test")
|
| 271 |
stopifnot(identical(1:10, S3Part(nn, strict = TRUE)))
|
271 |
stopifnot(identical(1:10, S3Part(nn, strict = TRUE)))
|
| 272 |
|
272 |
|
| 273 |
m1 = cbind(group, weight)
|
273 |
m1 = cbind(group, weight)
|
| 274 |
setClass("MatX", contains = "matrix", representation(date = "Date"))
|
274 |
setClass("MatX", contains = "matrix", representation(date = "Date"))
|
| 275 |
mx1 = new("MatX", m1, date = Sys.Date())
|
275 |
mx1 = new("MatX", m1, date = Sys.Date())
|
| 276 |
stopifnot(identical(m1, S3Part(mx1, strict = TRUE)))
|
276 |
stopifnot(identical(m1, S3Part(mx1, strict = TRUE)))
|
| 277 |
|
277 |
|