The R Project SVN R

Rev

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

Rev 44237 Rev 51304
Line 21... Line 21...
21
\alias{function-class}
21
\alias{function-class}
22
\alias{ANY-class}
22
\alias{ANY-class}
23
\alias{VIRTUAL-class}
23
\alias{VIRTUAL-class}
24
\alias{missing-class}
24
\alias{missing-class}
25
\alias{S4-class}
25
\alias{S4-class}
-
 
26
\alias{namedList-class}
26
\title{Classes Corresponding to Basic Data Types }
27
\title{Classes Corresponding to Basic Data Types }
27
\description{
28
\description{
28
  Formal classes exist corresponding to the basic R object types, allowing
29
  Formal classes exist corresponding to the basic R object types, allowing
29
  these types to be used in method signatures, as slots in class
30
  these types to be used in method signatures, as slots in class
30
  definitions, and to be extended by new classes.}
31
  definitions, and to be extended by new classes.}
Line 58... Line 59...
58
"externalptr" # raw external pointers for use in C code
59
"externalptr" # raw external pointers for use in C code
59
 
60
 
60
"ANY"  # virtual classes used by the methods package itself
61
"ANY"  # virtual classes used by the methods package itself
61
"VIRTUAL"
62
"VIRTUAL"
62
"missing"
63
"missing"
-
 
64
 
-
 
65
"namedList" # the alternative to "list" that preserves the names attribute
63
}
66
}
64
\section{Objects from the Classes}{
67
\section{Objects from the Classes}{
65
  Objects can be created by calls of the form \code{new(Class, ...)},
68
  Objects can be created by calls of the form \code{new(Class, ...)},
66
  where \code{Class} is the quoted class name, and the remaining
69
  where \code{Class} is the quoted class name, and the remaining
67
  arguments if any are objects to be interpreted as vectors of this
70
  arguments if any are objects to be interpreted as vectors of this
68
  class.  Multiple arguments will be concatenated.
71
  class.  Multiple arguments will be concatenated.
69
 
72
 
70
  The class \code{"expression"} is slightly odd, in that the \dots
73
  The class \code{"expression"} is slightly odd, in that the \dots
71
  arguments will \emph{not} be evaluated; therefore, don't enclose them
74
  arguments will \emph{not} be evaluated; therefore, don't enclose them
72
  in a call to \code{quote()}.
75
  in a call to \code{quote()}.
-
 
76
 
-
 
77
  Note that class \code{"list"} is a pure vector.  Although lists with
-
 
78
  names go back to the earliest versions of S, they are an extension
-
 
79
  of the vector concept in that they have an attribute (which can now
-
 
80
  be a slot) and which is either \code{NULL} or a character vector of
-
 
81
  the same length as the vector.  If you want to guarantee that list
-
 
82
  names are preserved, use class \code{"namedList"}, rather than
-
 
83
  \code{"list"}.  Objects from this class must have a names attribute,
-
 
84
  corresponding to slot \code{"names"},
-
 
85
  of type \code{"character"}.  Internally, R treats names for
-
 
86
  lists  specially, which makes it impractical to have the corresponding slot in
-
 
87
  class \code{"namedList"} be a union of character names and \code{NULL}.
-
 
88
 
73
}
89
}
-
 
90
 
-
 
91
\section{Classes and Types}{
-
 
92
The basic classes include classes for the basic R types.  Note that
-
 
93
objects of these types will not usually be S4 objects
-
 
94
(\code{\link{isS4}} will return \code{FALSE}), although objects from
-
 
95
classes that contain the basic class will be S4 objects, still with
-
 
96
the same type.  The type as
-
 
97
returned by \code{\link{typeof}} will sometimes differ from the class,
-
 
98
either just from a choice of terminology (type \code{"symbol"} and
-
 
99
class \code{"name"}, for example) or because there is not a one-to-one
-
 
100
correspondence between class and type (most of the classes that
-
 
101
inherit from class \code{"language"} have type \code{"language"}, for example).
-
 
102
}
-
 
103
 
-
 
104
 
74
\section{Extends}{
105
\section{Extends}{
75
  Class \code{"vector"}, directly.
106
  The vector classes extend \code{"vector"}, directly.
76
}
107
}
77
\section{Methods}{
108
\section{Methods}{
78
  \describe{
109
  \describe{
79
    \item{coerce}{Methods are defined to coerce arbitrary objects to
110
    \item{coerce}{Methods are defined to coerce arbitrary objects to
80
      these classes, by calling the corresponding basic function, for
111
      the vector classes, by calling the corresponding basic function, for
81
      example, \code{as(x, "numeric")} calls \code{as.numeric(x)}. }
112
      example, \code{as(x, "numeric")} calls \code{as.numeric(x)}. }
82
  }
113
  }
83
}
114
}
84
\keyword{classes}
115
\keyword{classes}