The R Project SVN R

Rev

Rev 27464 | Rev 32148 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27464 Rev 28043
Line 64... Line 64...
64
 
64
 
65
\note{
65
\note{
66
  Functions \code{oldClass} and \code{oldClass<-} behave in the same way
66
  Functions \code{oldClass} and \code{oldClass<-} behave in the same way
67
  as functions of those names in S-PLUS 5/6, \emph{but} in \R
67
  as functions of those names in S-PLUS 5/6, \emph{but} in \R
68
  \code{\link{UseMethod}} dispatches on the class as returned by
68
  \code{\link{UseMethod}} dispatches on the class as returned by
69
  \code{class} rather than \code{oldClass}.
69
  \code{class} rather than \code{oldClass}.  \emph{However},
-
 
70
  \link{group generic}s dispatch on the \code{oldClass} for efficiency.
70
}
71
}
71
 
72
 
72
\section{Formal classes}{
73
\section{Formal classes}{
73
  An additional mechanism of \emph{formal} classes has been available in
74
  An additional mechanism of \emph{formal} classes is available in
74
  packages \pkg{methods} since \R 1.4.0, and as from \R 1.7.0 this
75
  packages \pkg{methods} which is attached by default.  For objects
75
  is attached by default.  For objects which have a formal class, its name
76
  which have a formal class, its name is returned by \code{class}
76
  is returned by \code{class} as a character vector of length one.
77
  as a character vector of length one.
77
 
78
 
78
  The replacement version of the function sets the class to the value
79
  The replacement version of the function sets the class to the value
79
  provided.  For classes that have a formal definition, directly
80
  provided.  For classes that have a formal definition, directly
80
  replacing the class this way is strongly deprecated.  The expression
81
  replacing the class this way is strongly deprecated.  The expression
81
  \code{\link[methods]{as}(object, value)} is the way to coerce an object to a
82
  \code{\link[methods]{as}(object, value)} is the way to coerce an object to a
82
  particular class.
83
  particular class.
83
}
84
}
84
\seealso{
85
\seealso{
85
  \code{\link{UseMethod}}, \code{\link{NextMethod}}.
86
  \code{\link{UseMethod}}, \code{\link{NextMethod}},
-
 
87
  \code{\link{group generic}}.
86
}
88
}
87
\examples{
89
\examples{
88
  x <- 10
90
x <- 10
89
  inherits(x, "a") #FALSE
91
inherits(x, "a") #FALSE
90
  class(x)<-c("a", "b")
92
class(x) <- c("a", "b")
91
  inherits(x,"a") #TRUE
93
inherits(x,"a") #TRUE
92
  inherits(x, "a", TRUE) # 1
94
inherits(x, "a", TRUE) # 1
93
  inherits(x, c("a", "b", "c"), TRUE) # 1 2 0
95
inherits(x, c("a", "b", "c"), TRUE) # 1 2 0
94
}
96
}
95
\keyword{methods}
97
\keyword{methods}
96
\keyword{classes}
98
\keyword{classes}