| 60325 |
ripley |
1 |
% File src/library/methods/man/className.Rd
|
|
|
2 |
% Part of the R package, http://www.R-project.org
|
|
|
3 |
% Copyright 2011-2 R Core Team
|
|
|
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 56540 |
jmc |
6 |
\name{className}
|
|
|
7 |
\alias{className}
|
|
|
8 |
\alias{multipleClasses}
|
|
|
9 |
\alias{className-class}
|
|
|
10 |
\title{
|
|
|
11 |
Class names including the corresponding package
|
|
|
12 |
}
|
|
|
13 |
\description{
|
| 56541 |
jmc |
14 |
The function \code{className()} generates a
|
| 56540 |
jmc |
15 |
valid references to a class, including the name of the package
|
| 56541 |
jmc |
16 |
containing the class definition. The object returned, from class \code{"className"}, is the
|
| 56540 |
jmc |
17 |
unambiguous way to refer to a class, for example when calling
|
|
|
18 |
\code{\link{setMethod}}, just in case multiple definitions of the
|
|
|
19 |
class exist.
|
|
|
20 |
|
|
|
21 |
Function
|
|
|
22 |
\code{"multipleClasses"} returns information about multiple
|
|
|
23 |
definitions of classes with the
|
|
|
24 |
same name from different packages.
|
|
|
25 |
}
|
|
|
26 |
\usage{
|
|
|
27 |
|
|
|
28 |
className(class, package)
|
|
|
29 |
|
|
|
30 |
multipleClasses(details = FALSE)
|
|
|
31 |
}
|
|
|
32 |
\arguments{
|
|
|
33 |
|
|
|
34 |
\item{class, package}{
|
|
|
35 |
The character string name of a class and, optionally, of the package
|
|
|
36 |
to which it belongs. If argument \code{package} is missing and the
|
|
|
37 |
\code{class} argument has a package slot, that is used (in
|
|
|
38 |
particular, passing in an object from class \code{"className"} returns
|
|
|
39 |
itself in this case, but changes the package slot if the second
|
|
|
40 |
argument is supplied).
|
|
|
41 |
|
|
|
42 |
If there is no package argument or slot, a
|
|
|
43 |
definition for the class must exist and will be used to define the
|
|
|
44 |
package. If there are multiple definitions, one will be chosen and a
|
|
|
45 |
warning printed giving the other possibilities.
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
\item{details}{
|
|
|
49 |
If \code{FALSE}, the default, \code{multipleClasses()} returns a
|
|
|
50 |
character vector of those classes currently known with multiple
|
|
|
51 |
definitions.
|
|
|
52 |
|
|
|
53 |
If \code{TRUE}, a named list of those class definitions is returned.
|
| 56541 |
jmc |
54 |
Each element of the list is itself a list of the corresponding class
|
|
|
55 |
definitions, with the package names as the names of the list. Note
|
|
|
56 |
that identical class definitions will not be considered
|
|
|
57 |
\dQuote{multiple} definitions (see the discussion of the details below).
|
| 56540 |
jmc |
58 |
}
|
|
|
59 |
}
|
|
|
60 |
\details{
|
|
|
61 |
The table of class definitions used internally can maintain multiple
|
|
|
62 |
definitions for classes with the same name but coming from different
|
|
|
63 |
packages.
|
|
|
64 |
If identical class definitions are encountered, only one class
|
|
|
65 |
definition is kept; this occurs most often with S3 classes that have
|
| 56541 |
jmc |
66 |
been specified in calls to \code{\link{setOldClass}}. For true
|
| 56540 |
jmc |
67 |
classes, multiple class definitions are unavoidable in general if two
|
|
|
68 |
packages happen to have used the same name, independently.
|
|
|
69 |
|
| 56541 |
jmc |
70 |
Overriding a class definition in another package with the same name deliberately is usually a bad
|
| 56540 |
jmc |
71 |
idea.
|
|
|
72 |
Although \R attempts to keep and use the two definitions (as of
|
|
|
73 |
version 2.14.0), ambiguities are always possible. It is more
|
|
|
74 |
sensible to define a new class that extends an existing class but has
|
|
|
75 |
a different name.
|
|
|
76 |
}
|
|
|
77 |
\value{
|
|
|
78 |
A call to \code{className()} returns an object from class
|
|
|
79 |
\code{"className"}.
|
|
|
80 |
|
|
|
81 |
A call to \code{multipleClasses()} returns either a character
|
|
|
82 |
vector or a named list of class definitions. In either case, testing
|
|
|
83 |
the length of the returned value for being greater than \code{0} is a
|
|
|
84 |
check for the existence of multiply defined classes.
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
\section{Objects from the Class}{
|
|
|
88 |
The class \code{"className"} extends \code{"character"} and has a slot
|
|
|
89 |
\code{"package"}, also of class \code{"character"}.
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
\examples{
|
|
|
93 |
\dontrun{
|
|
|
94 |
className("vector") # will be found, from package "methods"
|
|
|
95 |
className("vector", "magic") # OK, even though the class doesn't exist
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
className("An unknown class") # Will cause an error
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
\keyword{ classes }
|
|
|
102 |
\keyword{ programming }
|