| 45824 |
jmc |
1 |
% File src/library/methods/man/findClass.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 68815 |
maechler |
3 |
% Copyright 1995-2015 R Core Team
|
| 45824 |
jmc |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
|
|
6 |
\name{findClass}
|
| 71366 |
jmc |
7 |
\title{Find Class Definitions}
|
| 45824 |
jmc |
8 |
\alias{removeClass}
|
|
|
9 |
\alias{resetClass}
|
|
|
10 |
\alias{isClass}
|
|
|
11 |
\alias{getClasses}
|
| 56186 |
murdoch |
12 |
\alias{findClass}
|
| 45824 |
jmc |
13 |
\alias{sealClass}
|
|
|
14 |
\description{
|
| 71366 |
jmc |
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}}.
|
| 45824 |
jmc |
19 |
}
|
|
|
20 |
\usage{
|
|
|
21 |
isClass(Class, formal=TRUE, where)
|
|
|
22 |
|
|
|
23 |
getClasses(where, inherits = missing(where))
|
|
|
24 |
|
|
|
25 |
findClass(Class, where, unique = "")
|
|
|
26 |
|
| 71366 |
jmc |
27 |
## The remaining functions are retained for compatibility
|
|
|
28 |
## but not generally recommended
|
|
|
29 |
|
| 70554 |
lawrence |
30 |
removeClass(Class, where)
|
| 68815 |
maechler |
31 |
|
| 45824 |
jmc |
32 |
resetClass(Class, classDef, where)
|
|
|
33 |
|
|
|
34 |
sealClass(Class, where)
|
|
|
35 |
|
|
|
36 |
}
|
|
|
37 |
\arguments{
|
| 45885 |
maechler |
38 |
\item{Class}{character string name for the class. The functions will
|
|
|
39 |
usually take a class definition instead of the string. To restrict
|
|
|
40 |
the class to those defined in a particular package, set the
|
|
|
41 |
\code{\link{packageSlot}} of the character string.}
|
| 71366 |
jmc |
42 |
\item{where}{the \code{\link{environment}} in which to search for
|
|
|
43 |
the class definition. Defaults to the top-level environment of the
|
|
|
44 |
calling function. When called from the command line, this has the
|
|
|
45 |
effect of using all the package environments in the search list.
|
| 45824 |
jmc |
46 |
|
| 71366 |
jmc |
47 |
To restrict the search to classes in a particular package, use \code{where =
|
|
|
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
|
|
|
51 |
package is attached to the search list.
|
| 45824 |
jmc |
52 |
}
|
| 71366 |
jmc |
53 |
\item{formal}{\code{\link{logical}} is a formal definition
|
|
|
54 |
required? For S compatibility, and always treated as \code{TRUE}.}
|
| 45824 |
jmc |
55 |
\item{unique}{if \code{findClass} expects a unique location for the
|
|
|
56 |
class, \code{unique} is a character string explaining the purpose
|
|
|
57 |
of the search (and is used in warning and error messages). By
|
|
|
58 |
default, multiple locations are possible and the function always
|
|
|
59 |
returns a list.
|
|
|
60 |
}
|
|
|
61 |
\item{inherits}{in a call to \code{getClasses}, should the value
|
|
|
62 |
returned include all parent environments of \code{where}, or that
|
|
|
63 |
environment only? Defaults to \code{TRUE} if \code{where} is
|
|
|
64 |
omitted, and to \code{FALSE} otherwise.
|
|
|
65 |
}
|
| 68815 |
maechler |
66 |
\item{classDef}{ For \code{resetClass}, the optional class
|
| 71366 |
jmc |
67 |
definition.
|
| 45824 |
jmc |
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
| 71366 |
jmc |
71 |
\section{Functions}{
|
| 45824 |
jmc |
72 |
|
|
|
73 |
\describe{
|
|
|
74 |
\item{\code{isClass}:}{
|
| 71366 |
jmc |
75 |
Is this the name of a formally defined class?
|
| 45824 |
jmc |
76 |
}
|
|
|
77 |
\item{\code{getClasses}:}{
|
|
|
78 |
The names of all the classes formally defined on \code{where}. If
|
|
|
79 |
called with no argument, all the classes visible from the
|
|
|
80 |
calling function (if called from the top-level, all the classes
|
|
|
81 |
in any of the environments on the search list). The
|
| 71366 |
jmc |
82 |
\code{where} argument is used to search only in a particular package.
|
| 45824 |
jmc |
83 |
}
|
|
|
84 |
\item{\code{findClass}:}{
|
| 71366 |
jmc |
85 |
The list of environments in
|
| 45824 |
jmc |
86 |
which a class definition of \code{Class} is found. If
|
| 71366 |
jmc |
87 |
\code{where} is supplied, a list is still returned, either empty
|
|
|
88 |
or containing the environment corresponding to \code{where}.
|
|
|
89 |
By default when called from the \R session, the global
|
|
|
90 |
environment and all the currently
|
|
|
91 |
attached packages are searched.
|
| 45824 |
jmc |
92 |
|
|
|
93 |
If \code{unique} is supplied as a character string,
|
|
|
94 |
\code{findClass} will warn if there is more than one definition
|
|
|
95 |
visible (using the string to identify the purpose of the call),
|
|
|
96 |
and will generate an error if no definition can be found.
|
| 71366 |
jmc |
97 |
|
|
|
98 |
\emph{The remaining functions are retained for
|
|
|
99 |
back-compatibility and internal use, but not generally recommended.}
|
| 45824 |
jmc |
100 |
}
|
| 71366 |
jmc |
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.
|
|
|
105 |
}
|
| 45824 |
jmc |
106 |
\item{\code{resetClass}:}{
|
| 71366 |
jmc |
107 |
Reset the internal definition of a class. Not legitimate for a
|
|
|
108 |
class definition not in this package and rarely needed otherwise.
|
| 45824 |
jmc |
109 |
}
|
|
|
110 |
\item{\code{sealClass}:}{ Seal the current definition of the specified
|
| 71366 |
jmc |
111 |
class, to prevent further changes, by setting the corresponding
|
|
|
112 |
slot in the class definition. This is rarely used, since
|
|
|
113 |
classes in loaded packages are sealed by locking their namespace.
|
| 45824 |
jmc |
114 |
}
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
\references{
|
| 88585 |
hornik |
119 |
\bibshow{R:Chambers:2016}
|
|
|
120 |
(Chapters 9 and 10.)
|
| 71366 |
jmc |
121 |
|
| 88589 |
hornik |
122 |
\bibshow{R:Chambers:2008}
|
|
|
123 |
(Chapter 9 has some details not in the later reference.)
|
| 71366 |
jmc |
124 |
}
|
| 45824 |
jmc |
125 |
|
|
|
126 |
\seealso{
|
| 71366 |
jmc |
127 |
\code{\link{getClass}},
|
|
|
128 |
\code{\link{Classes_Details}},
|
|
|
129 |
\code{\link{Methods_Details}},
|
| 45824 |
jmc |
130 |
\code{\link{makeClassRepresentation}}
|
|
|
131 |
}
|
|
|
132 |
%% should add Examples section
|
|
|
133 |
\keyword{programming}
|
|
|
134 |
\keyword{classes}
|
|
|
135 |
\keyword{methods}
|