| 42333 |
ripley |
1 |
% File src/library/methods/man/getClass.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 68815 |
maechler |
3 |
% Copyright 1995-2015 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 15357 |
jmc |
6 |
\name{getClass}
|
| 56186 |
murdoch |
7 |
\alias{getClass}
|
| 15357 |
jmc |
8 |
\alias{getClassDef}
|
| 15852 |
jmc |
9 |
\title{Get Class Definition }
|
| 15357 |
jmc |
10 |
\description{
|
|
|
11 |
Get the definition of a class.
|
|
|
12 |
}
|
|
|
13 |
\usage{
|
| 70554 |
lawrence |
14 |
getClass (Class, .Force = FALSE, where)
|
|
|
15 |
getClassDef(Class, where, package, inherits = TRUE)
|
| 15357 |
jmc |
16 |
}
|
|
|
17 |
\arguments{
|
| 48218 |
jmc |
18 |
\item{Class}{ the character-string name of the class, often with a
|
|
|
19 |
\code{"package"} attribute as noted below under \code{package}.}
|
| 16559 |
jmc |
20 |
\item{.Force}{ if \code{TRUE}, return \code{NULL} if the class is
|
| 19029 |
hornik |
21 |
undefined; otherwise, an undefined class results in an error.}
|
| 25351 |
jmc |
22 |
\item{where}{ environment from which to begin the search for the definition; by default,
|
|
|
23 |
start at the top-level (global) environment and proceed through
|
|
|
24 |
the search list.}
|
| 74656 |
lawrence |
25 |
\item{package}{ the name or environment of the package asserted to hold the
|
| 48218 |
jmc |
26 |
definition. If it is a non-empty string it is used instead of
|
|
|
27 |
\code{where}, as the first place to look for the class.
|
|
|
28 |
Note that the package must be loaded but need not be attached. By
|
|
|
29 |
default, the package attribute of the \code{Class} argument is
|
|
|
30 |
used, if any. There will usually be a package attribute if
|
|
|
31 |
\code{Class} comes from \code{class(x)} for some object.
|
|
|
32 |
}
|
| 68815 |
maechler |
33 |
\item{inherits}{logical; should the class definition be retrieved from
|
|
|
34 |
any enclosing environment and also from the cache? If \code{FALSE}
|
|
|
35 |
only a definition in the environment \code{where} will be returned.}
|
| 15357 |
jmc |
36 |
}
|
|
|
37 |
\details{
|
| 48218 |
jmc |
38 |
Class definitions are stored in metadata objects in a package
|
|
|
39 |
namespace or other environment where they are defined. When
|
|
|
40 |
packages are loaded, the class definitions in the package are cached in an internal
|
|
|
41 |
table. Therefore, most calls to \code{getClassDef} will find the
|
|
|
42 |
class in the cache or fail to find it at all, unless \code{inherits}
|
|
|
43 |
is \code{FALSE}, in which case only the environment(s) defined by
|
|
|
44 |
\code{package} or \code{where} are searched.
|
| 15357 |
jmc |
45 |
|
| 48218 |
jmc |
46 |
The class cache allows for multiple definitions of the
|
|
|
47 |
same class name in separate environments, with of course the
|
|
|
48 |
limitation that the package attribute or package name must be
|
| 61433 |
ripley |
49 |
provided in the call to
|
| 48218 |
jmc |
50 |
|
| 15357 |
jmc |
51 |
}
|
|
|
52 |
\value{
|
| 48218 |
jmc |
53 |
The object defining the class. If the class definition is not found,
|
|
|
54 |
\code{getClassDef} returns \code{NULL}, while \code{getClass}, which
|
|
|
55 |
calls \code{getClassDef}, either generates an error or, if
|
|
|
56 |
\code{.Force} is \code{TRUE}, returns a simple definition for the
|
|
|
57 |
class. The latter case is used internally, but is not typically
|
|
|
58 |
sensible in user code.
|
|
|
59 |
|
|
|
60 |
The non-null returned value is an object of class
|
| 71548 |
jmc |
61 |
\code{\linkS4class{classRepresentation}}.
|
|
|
62 |
|
|
|
63 |
Use functions such as \code{\link{setClass}} and
|
|
|
64 |
\code{\link{setClassUnion}} to create class definitions.
|
| 15357 |
jmc |
65 |
}
|
|
|
66 |
\references{
|
| 71548 |
jmc |
67 |
Chambers, John M. (2016)
|
|
|
68 |
\emph{Extending R},
|
|
|
69 |
Chapman & Hall.
|
|
|
70 |
(Chapters 9 and 10.)
|
|
|
71 |
}
|
| 15357 |
jmc |
72 |
|
| 19029 |
hornik |
73 |
\seealso{
|
| 71548 |
jmc |
74 |
\linkS4class{classRepresentation},
|
| 19029 |
hornik |
75 |
\code{\link{setClass}},
|
|
|
76 |
\code{\link{isClass}}.
|
|
|
77 |
}
|
| 15357 |
jmc |
78 |
\examples{
|
|
|
79 |
getClass("numeric") ## a built in class
|
|
|
80 |
|
| 33558 |
maechler |
81 |
cld <- getClass("thisIsAnUndefinedClass", .Force = TRUE)
|
|
|
82 |
cld ## a NULL prototype
|
|
|
83 |
## If you are really curious:
|
| 41508 |
ripley |
84 |
utils::str(cld)
|
| 33558 |
maechler |
85 |
## Whereas these generate errors:
|
|
|
86 |
try(getClass("thisIsAnUndefinedClass"))
|
|
|
87 |
try(getClassDef("thisIsAnUndefinedClass"))
|
| 15357 |
jmc |
88 |
}
|
|
|
89 |
\keyword{programming}
|
|
|
90 |
\keyword{classes}
|