| 42333 |
ripley |
1 |
% File src/library/methods/man/BasicClasses.Rd
|
|
|
2 |
% Part of the R package, http://www.R-project.org
|
| 59039 |
ripley |
3 |
% Copyright 1995-2007 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 19087 |
jmc |
6 |
\name{BasicClasses}
|
|
|
7 |
\docType{class}
|
|
|
8 |
\alias{character-class}
|
|
|
9 |
\alias{complex-class}
|
|
|
10 |
\alias{double-class}
|
|
|
11 |
\alias{expression-class}
|
| 20092 |
jmc |
12 |
\alias{externalptr-class}
|
| 19087 |
jmc |
13 |
\alias{integer-class}
|
|
|
14 |
\alias{list-class}
|
|
|
15 |
\alias{logical-class}
|
|
|
16 |
\alias{numeric-class}
|
| 31845 |
ripley |
17 |
\alias{raw-class}
|
| 19087 |
jmc |
18 |
\alias{single-class}
|
|
|
19 |
\alias{vector-class}
|
|
|
20 |
\alias{NULL-class}
|
| 56219 |
jmc |
21 |
\alias{builtin-class}
|
|
|
22 |
\alias{special-class}
|
| 19087 |
jmc |
23 |
\alias{function-class}
|
|
|
24 |
\alias{ANY-class}
|
|
|
25 |
\alias{VIRTUAL-class}
|
|
|
26 |
\alias{missing-class}
|
| 44237 |
jmc |
27 |
\alias{S4-class}
|
| 51304 |
jmc |
28 |
\alias{namedList-class}
|
| 19087 |
jmc |
29 |
\title{Classes Corresponding to Basic Data Types }
|
| 23531 |
hornik |
30 |
\description{
|
| 44237 |
jmc |
31 |
Formal classes exist corresponding to the basic R object types, allowing
|
| 23531 |
hornik |
32 |
these types to be used in method signatures, as slots in class
|
|
|
33 |
definitions, and to be extended by new classes.}
|
| 19087 |
jmc |
34 |
\usage{
|
|
|
35 |
### The following are all basic vector classes.
|
|
|
36 |
### They can appear as class names in method signatures,
|
|
|
37 |
### in calls to as(), is(), and new().
|
|
|
38 |
"character"
|
|
|
39 |
"complex"
|
|
|
40 |
"double"
|
|
|
41 |
"expression"
|
|
|
42 |
"integer"
|
|
|
43 |
"list"
|
|
|
44 |
"logical"
|
|
|
45 |
"numeric"
|
|
|
46 |
"single"
|
| 31845 |
ripley |
47 |
"raw"
|
| 19087 |
jmc |
48 |
|
|
|
49 |
### the class
|
|
|
50 |
"vector"
|
|
|
51 |
### is a virtual class, extended by all the above
|
|
|
52 |
|
| 44237 |
jmc |
53 |
### the class
|
|
|
54 |
"S4"
|
|
|
55 |
### is an object type for S4 objects that do not extend
|
|
|
56 |
### any of the basic vector classes. It is a virtual class.
|
|
|
57 |
|
| 19087 |
jmc |
58 |
### The following are additional basic classes
|
|
|
59 |
"NULL" # NULL objects
|
|
|
60 |
"function" # function objects, including primitives
|
| 20092 |
jmc |
61 |
"externalptr" # raw external pointers for use in C code
|
| 19087 |
jmc |
62 |
|
|
|
63 |
"ANY" # virtual classes used by the methods package itself
|
|
|
64 |
"VIRTUAL"
|
|
|
65 |
"missing"
|
| 51304 |
jmc |
66 |
|
| 56280 |
ripley |
67 |
"namedList" # the alternative to "list" that preserves
|
|
|
68 |
# the names attribute
|
| 19087 |
jmc |
69 |
}
|
|
|
70 |
\section{Objects from the Classes}{
|
| 60964 |
maechler |
71 |
If a class is not virtual (see section in \code{\link{Classes}}),
|
|
|
72 |
objects can be created by calls of the form \code{new(Class, ...)},
|
| 23531 |
hornik |
73 |
where \code{Class} is the quoted class name, and the remaining
|
|
|
74 |
arguments if any are objects to be interpreted as vectors of this
|
|
|
75 |
class. Multiple arguments will be concatenated.
|
| 19087 |
jmc |
76 |
|
| 23531 |
hornik |
77 |
The class \code{"expression"} is slightly odd, in that the \dots
|
|
|
78 |
arguments will \emph{not} be evaluated; therefore, don't enclose them
|
|
|
79 |
in a call to \code{quote()}.
|
| 51304 |
jmc |
80 |
|
|
|
81 |
Note that class \code{"list"} is a pure vector. Although lists with
|
|
|
82 |
names go back to the earliest versions of S, they are an extension
|
|
|
83 |
of the vector concept in that they have an attribute (which can now
|
|
|
84 |
be a slot) and which is either \code{NULL} or a character vector of
|
|
|
85 |
the same length as the vector. If you want to guarantee that list
|
|
|
86 |
names are preserved, use class \code{"namedList"}, rather than
|
|
|
87 |
\code{"list"}. Objects from this class must have a names attribute,
|
|
|
88 |
corresponding to slot \code{"names"},
|
|
|
89 |
of type \code{"character"}. Internally, R treats names for
|
|
|
90 |
lists specially, which makes it impractical to have the corresponding slot in
|
|
|
91 |
class \code{"namedList"} be a union of character names and \code{NULL}.
|
|
|
92 |
|
| 19087 |
jmc |
93 |
}
|
| 51304 |
jmc |
94 |
|
|
|
95 |
\section{Classes and Types}{
|
|
|
96 |
The basic classes include classes for the basic R types. Note that
|
|
|
97 |
objects of these types will not usually be S4 objects
|
|
|
98 |
(\code{\link{isS4}} will return \code{FALSE}), although objects from
|
|
|
99 |
classes that contain the basic class will be S4 objects, still with
|
|
|
100 |
the same type. The type as
|
|
|
101 |
returned by \code{\link{typeof}} will sometimes differ from the class,
|
|
|
102 |
either just from a choice of terminology (type \code{"symbol"} and
|
|
|
103 |
class \code{"name"}, for example) or because there is not a one-to-one
|
|
|
104 |
correspondence between class and type (most of the classes that
|
|
|
105 |
inherit from class \code{"language"} have type \code{"language"}, for example).
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
|
| 19087 |
jmc |
109 |
\section{Extends}{
|
| 51304 |
jmc |
110 |
The vector classes extend \code{"vector"}, directly.
|
| 19087 |
jmc |
111 |
}
|
|
|
112 |
\section{Methods}{
|
|
|
113 |
\describe{
|
|
|
114 |
\item{coerce}{Methods are defined to coerce arbitrary objects to
|
| 51304 |
jmc |
115 |
the vector classes, by calling the corresponding basic function, for
|
| 19087 |
jmc |
116 |
example, \code{as(x, "numeric")} calls \code{as.numeric(x)}. }
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
\keyword{classes}
|