| Line 2... |
Line 2... |
| 2 |
% Part of the R package, https://www.R-project.org
|
2 |
% Part of the R package, https://www.R-project.org
|
| 3 |
% Copyright 1995-2015 R Core Team
|
3 |
% Copyright 1995-2015 R Core Team
|
| 4 |
% Distributed under GPL 2 or later
|
4 |
% Distributed under GPL 2 or later
|
| 5 |
|
5 |
|
| 6 |
\name{findClass}
|
6 |
\name{findClass}
|
| 7 |
\title{Computations with Classes}
|
7 |
\title{Find Class Definitions}
|
| 8 |
\alias{removeClass}
|
8 |
\alias{removeClass}
|
| 9 |
\alias{resetClass}
|
9 |
\alias{resetClass}
|
| 10 |
\alias{isClass}
|
10 |
\alias{isClass}
|
| 11 |
\alias{getClasses}
|
11 |
\alias{getClasses}
|
| 12 |
\alias{findClass}
|
12 |
\alias{findClass}
|
| 13 |
\alias{sealClass}
|
13 |
\alias{sealClass}
|
| 14 |
\description{
|
14 |
\description{
|
| 15 |
Functions to find and manipulate class definitions.
|
15 |
Functions to find classes: \code{isClass} tests for a class;
|
| - |
|
16 |
\code{findClass} returns the name(s) of packages containing the
|
| - |
|
17 |
class; \code{getClasses} returns the names of all the classes in an
|
| - |
|
18 |
environment, typically a namespace. To examine the definition of a class, use \code{\link{getClass}}.
|
| 16 |
}
|
19 |
}
|
| 17 |
\usage{
|
20 |
\usage{
|
| 18 |
isClass(Class, formal=TRUE, where)
|
21 |
isClass(Class, formal=TRUE, where)
|
| 19 |
|
22 |
|
| 20 |
getClasses(where, inherits = missing(where))
|
23 |
getClasses(where, inherits = missing(where))
|
| 21 |
|
24 |
|
| 22 |
findClass(Class, where, unique = "")
|
25 |
findClass(Class, where, unique = "")
|
| 23 |
|
26 |
|
| - |
|
27 |
## The remaining functions are retained for compatibility
|
| - |
|
28 |
## but not generally recommended
|
| - |
|
29 |
|
| 24 |
removeClass(Class, where)
|
30 |
removeClass(Class, where)
|
| 25 |
|
31 |
|
| 26 |
resetClass(Class, classDef, where)
|
32 |
resetClass(Class, classDef, where)
|
| 27 |
|
33 |
|
| 28 |
sealClass(Class, where)
|
34 |
sealClass(Class, where)
|
| Line 31... |
Line 37... |
| 31 |
\arguments{
|
37 |
\arguments{
|
| 32 |
\item{Class}{character string name for the class. The functions will
|
38 |
\item{Class}{character string name for the class. The functions will
|
| 33 |
usually take a class definition instead of the string. To restrict
|
39 |
usually take a class definition instead of the string. To restrict
|
| 34 |
the class to those defined in a particular package, set the
|
40 |
the class to those defined in a particular package, set the
|
| 35 |
\code{\link{packageSlot}} of the character string.}
|
41 |
\code{\link{packageSlot}} of the character string.}
|
| 36 |
\item{where}{the \code{\link{environment}} in which to modify or
|
42 |
\item{where}{the \code{\link{environment}} in which to search for
|
| 37 |
remove the definition. Defaults to the top-level environment of the
|
43 |
the class definition. Defaults to the top-level environment of the
|
| 38 |
calling function (the global environment for ordinary computations,
|
44 |
calling function. When called from the command line, this has the
|
| 39 |
but the environment or namespace of a package in the source for a
|
45 |
effect of using all the package environments in the search list.
|
| 40 |
package).
|
- |
|
| 41 |
|
46 |
|
| 42 |
When searching for class definitions, \code{where} defines where to
|
47 |
To restrict the search to classes in a particular package, use \code{where =
|
| 43 |
do the search, and the default is to search from the top-level
|
48 |
asNamespace(pkg)} with \code{pkg} the package name; to restrict
|
| - |
|
49 |
it to
|
| - |
|
50 |
the \emph{exported} classes, use \code{where = "package:pkg"} after the
|
| 44 |
environment or namespace of the caller to this function.
|
51 |
package is attached to the search list.
|
| 45 |
}
|
52 |
}
|
| 46 |
\item{formal}{\code{\link{logical}} indicating if a formal definition
|
53 |
\item{formal}{\code{\link{logical}} is a formal definition
|
| 47 |
is required.}
|
54 |
required? For S compatibility, and always treated as \code{TRUE}.}
|
| 48 |
\item{unique}{if \code{findClass} expects a unique location for the
|
55 |
\item{unique}{if \code{findClass} expects a unique location for the
|
| 49 |
class, \code{unique} is a character string explaining the purpose
|
56 |
class, \code{unique} is a character string explaining the purpose
|
| 50 |
of the search (and is used in warning and error messages). By
|
57 |
of the search (and is used in warning and error messages). By
|
| 51 |
default, multiple locations are possible and the function always
|
58 |
default, multiple locations are possible and the function always
|
| 52 |
returns a list.
|
59 |
returns a list.
|
| Line 55... |
Line 62... |
| 55 |
returned include all parent environments of \code{where}, or that
|
62 |
returned include all parent environments of \code{where}, or that
|
| 56 |
environment only? Defaults to \code{TRUE} if \code{where} is
|
63 |
environment only? Defaults to \code{TRUE} if \code{where} is
|
| 57 |
omitted, and to \code{FALSE} otherwise.
|
64 |
omitted, and to \code{FALSE} otherwise.
|
| 58 |
}
|
65 |
}
|
| 59 |
\item{classDef}{ For \code{resetClass}, the optional class
|
66 |
\item{classDef}{ For \code{resetClass}, the optional class
|
| 60 |
definition (but usually it's better for \code{Class} to be the
|
- |
|
| 61 |
class definition, and to omit \code{classDef}).
|
67 |
definition.
|
| 62 |
}
|
68 |
}
|
| 63 |
}
|
69 |
}
|
| 64 |
|
70 |
|
| 65 |
\details{
|
71 |
\section{Functions}{
|
| 66 |
These are the functions that test and manipulate formal class
|
- |
|
| 67 |
definitions. Brief documentation is provided below. See the
|
- |
|
| 68 |
references for an introduction and for more details.
|
- |
|
| 69 |
|
72 |
|
| 70 |
\describe{
|
73 |
\describe{
|
| 71 |
\item{\code{removeClass}:}{
|
- |
|
| 72 |
Remove the definition of this class, from the environment
|
- |
|
| 73 |
\code{where} if this argument is supplied; if not,
|
- |
|
| 74 |
\code{removeClass} will search for a definition, starting in the
|
- |
|
| 75 |
top-level environment of the call to \code{removeClass}, and
|
- |
|
| 76 |
remove the (first) definition found.
|
- |
|
| 77 |
}
|
- |
|
| 78 |
\item{\code{isClass}:}{
|
74 |
\item{\code{isClass}:}{
|
| 79 |
Is this the name of a formally defined class? (Argument
|
75 |
Is this the name of a formally defined class?
|
| 80 |
\code{formal} is for compatibility and is ignored.)
|
- |
|
| 81 |
}
|
76 |
}
|
| 82 |
\item{\code{getClasses}:}{
|
77 |
\item{\code{getClasses}:}{
|
| 83 |
The names of all the classes formally defined on \code{where}. If
|
78 |
The names of all the classes formally defined on \code{where}. If
|
| 84 |
called with no argument, all the classes visible from the
|
79 |
called with no argument, all the classes visible from the
|
| 85 |
calling function (if called from the top-level, all the classes
|
80 |
calling function (if called from the top-level, all the classes
|
| 86 |
in any of the environments on the search list). The
|
81 |
in any of the environments on the search list). The
|
| 87 |
\code{inherits} argument can be used to search a particular
|
82 |
\code{where} argument is used to search only in a particular package.
|
| 88 |
environment and all its parents, but usually the default setting
|
- |
|
| 89 |
is what you want.
|
- |
|
| 90 |
}
|
83 |
}
|
| 91 |
\item{\code{findClass}:}{
|
84 |
\item{\code{findClass}:}{
|
| 92 |
The list of environments or positions on the search list in
|
85 |
The list of environments in
|
| 93 |
which a class definition of \code{Class} is found. If
|
86 |
which a class definition of \code{Class} is found. If
|
| 94 |
\code{where} is supplied, this is an environment (or namespace)
|
87 |
\code{where} is supplied, a list is still returned, either empty
|
| 95 |
from which the search takes place; otherwise the top-level
|
88 |
or containing the environment corresponding to \code{where}.
|
| 96 |
environment of the caller is used. If \code{unique} is supplied
|
89 |
By default when called from the \R session, the global
|
| 97 |
as a character string, \code{findClass} returns a single
|
- |
|
| 98 |
environment or position. By default, it always returns a list.
|
90 |
environment and all the currently
|
| 99 |
The calling function should select, say, the first element as a
|
91 |
attached packages are searched.
|
| 100 |
position or environment for functions such as \code{\link{get}}.
|
- |
|
| 101 |
|
92 |
|
| 102 |
If \code{unique} is supplied as a character string,
|
93 |
If \code{unique} is supplied as a character string,
|
| 103 |
\code{findClass} will warn if there is more than one definition
|
94 |
\code{findClass} will warn if there is more than one definition
|
| 104 |
visible (using the string to identify the purpose of the call),
|
95 |
visible (using the string to identify the purpose of the call),
|
| 105 |
and will generate an error if no definition can be found.
|
96 |
and will generate an error if no definition can be found.
|
| - |
|
97 |
|
| - |
|
98 |
\emph{The remaining functions are retained for
|
| - |
|
99 |
back-compatibility and internal use, but not generally recommended.}
|
| - |
|
100 |
}
|
| - |
|
101 |
\item{\code{removeClass}:}{
|
| - |
|
102 |
Remove the definition of this class. This can't be used if the
|
| - |
|
103 |
class is in another package, and would rarely be needed in
|
| - |
|
104 |
source code defining classes in a package.
|
| 106 |
}
|
105 |
}
|
| 107 |
\item{\code{resetClass}:}{
|
106 |
\item{\code{resetClass}:}{
|
| 108 |
Reset the internal definition of a class. Causes the complete
|
107 |
Reset the internal definition of a class. Not legitimate for a
|
| 109 |
definition of the class to be re-computed, from the
|
108 |
class definition not in this package and rarely needed otherwise.
|
| 110 |
representation and superclasses specified in the original
|
- |
|
| 111 |
call to \code{setClass}.
|
- |
|
| 112 |
|
- |
|
| 113 |
This function is called when aspects of the class definition are
|
- |
|
| 114 |
changed. You would need to call it explicitly if you changed the
|
- |
|
| 115 |
definition of a class that this class extends (but doing that in
|
- |
|
| 116 |
the middle of a session is living dangerously, since it may
|
- |
|
| 117 |
invalidate existing objects).
|
- |
|
| 118 |
}
|
109 |
}
|
| 119 |
\item{\code{sealClass}:}{ Seal the current definition of the specified
|
110 |
\item{\code{sealClass}:}{ Seal the current definition of the specified
|
| 120 |
class, to prevent further changes. It is possible to seal a class
|
111 |
class, to prevent further changes, by setting the corresponding
|
| 121 |
in the call to \code{setClass}, but sometimes further changes have
|
112 |
slot in the class definition. This is rarely used, since
|
| 122 |
to be made (e.g., by calls to \code{setIs}). If so, call
|
- |
|
| 123 |
\code{sealClass} after all the relevant changes have been made.
|
113 |
classes in loaded packages are sealed by locking their namespace.
|
| 124 |
}
|
114 |
}
|
| 125 |
}
|
115 |
}
|
| 126 |
}
|
116 |
}
|
| 127 |
|
117 |
|
| 128 |
\references{
|
118 |
\references{
|
| - |
|
119 |
Chambers, John M. (2016)
|
| - |
|
120 |
\emph{Extending R},
|
| - |
|
121 |
Chapman & Hall.
|
| - |
|
122 |
(Chapters 9 and 10.)
|
| - |
|
123 |
|
| 129 |
Chambers, John M. (2008)
|
124 |
Chambers, John M. (2008)
|
| 130 |
\emph{Software for Data Analysis: Programming with R}
|
125 |
\emph{Software for Data Analysis: Programming with R}
|
| 131 |
Springer. (For the R version.)
|
- |
|
| 132 |
|
- |
|
| 133 |
Chambers, John M. (1998)
|
- |
|
| 134 |
\emph{Programming with Data}
|
- |
|
| 135 |
Springer (For the original S4 version.)
|
126 |
Springer. (Chapter 9 has some details not in the later reference.)
|
| 136 |
}
|
127 |
}
|
| - |
|
128 |
|
| 137 |
\seealso{
|
129 |
\seealso{
|
| 138 |
\code{\link{setClassUnion}},
|
130 |
\code{\link{getClass}},
|
| - |
|
131 |
\code{\link{Classes_Details}},
|
| 139 |
\code{\link{Methods}},
|
132 |
\code{\link{Methods_Details}},
|
| 140 |
\code{\link{makeClassRepresentation}}
|
133 |
\code{\link{makeClassRepresentation}}
|
| 141 |
}
|
134 |
}
|
| 142 |
%% should add Examples section
|
135 |
%% should add Examples section
|
| 143 |
\keyword{programming}
|
136 |
\keyword{programming}
|
| 144 |
\keyword{classes}
|
137 |
\keyword{classes}
|