| 48079 |
jmc |
1 |
\name{classesToAM}
|
| 56186 |
murdoch |
2 |
\alias{classesToAM}
|
| 48079 |
jmc |
3 |
\title{
|
| 52784 |
murdoch |
4 |
Compute an Adjacency Matrix for Superclasses of Class Definitions
|
| 48079 |
jmc |
5 |
}
|
|
|
6 |
\description{
|
|
|
7 |
Given a vector of class names or a list of class definitions, the
|
|
|
8 |
function returns an adjacency matrix of the superclasses of these
|
|
|
9 |
classes; that is, a matrix with class names as the row and column
|
|
|
10 |
names and with element [i, j] being 1 if the class in column j is a
|
|
|
11 |
direct superclass of the class in row i, and 0 otherwise.
|
|
|
12 |
|
|
|
13 |
The matrix has the information implied by the \code{contains} slot of
|
|
|
14 |
the class definitions, but in a form that is often more convenient for
|
|
|
15 |
further analysis; for example, an adjacency matrix is used in packages
|
|
|
16 |
and other software to construct graph representations of relationships.
|
|
|
17 |
}
|
|
|
18 |
\usage{
|
|
|
19 |
classesToAM(classes, includeSubclasses = FALSE,
|
|
|
20 |
abbreviate = 2)
|
|
|
21 |
}
|
|
|
22 |
\arguments{
|
|
|
23 |
\item{classes}{
|
|
|
24 |
Either a character vector of class names or a list, whose
|
|
|
25 |
elements can be either class names or class definitions. The
|
|
|
26 |
list is convenient, for example, to include the package slot for
|
|
|
27 |
the class name. See the examples.
|
|
|
28 |
}
|
|
|
29 |
\item{includeSubclasses}{
|
|
|
30 |
A logical flag; if \code{TRUE}, then the matrix will include all
|
|
|
31 |
the known subclasses of the specified classes as well as the
|
|
|
32 |
superclasses. The argument can also be a logical vector of the
|
|
|
33 |
same length as \code{classes}, to include subclasses for some
|
|
|
34 |
but not all the classes.
|
|
|
35 |
}
|
|
|
36 |
\item{abbreviate}{
|
|
|
37 |
Control of the abbreviation of the row and/or column labels of
|
|
|
38 |
the matrix returned: values 0, 1, 2, or 3 abbreviate neither,
|
|
|
39 |
rows, columns or both. The default, 2, is useful for printing
|
|
|
40 |
the matrix, since class names tend to be more than one
|
|
|
41 |
character long, making for spread-out printing. Values of 0
|
|
|
42 |
or 3 would be appropriate for making a graph (3 avoids the
|
|
|
43 |
tendency of some graph plotting software to produce labels in
|
|
|
44 |
minuscule font size).
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
\details{
|
|
|
48 |
For each of the classes, the calculation gets all the superclass
|
|
|
49 |
names from the class definition, and finds the edges in those classes'
|
|
|
50 |
definitions; that is, all the superclasses at distance 1. The
|
|
|
51 |
corresponding elements of the adjacency matrix are set to 1.
|
|
|
52 |
|
|
|
53 |
The adjacency matrices for the individual class definitions are
|
|
|
54 |
merged. Note two possible kinds of inconsistency, neither of which
|
|
|
55 |
should cause problems except possibly with identically named classes from
|
|
|
56 |
different packages. Edges are computed from each superclass
|
|
|
57 |
definition, so that information overrides a possible inference from
|
|
|
58 |
extension elements with distance > 1 (and it should). When
|
|
|
59 |
matrices from successive classes in the argument are merged, the
|
|
|
60 |
computations do not currently check for inconsistencies---this is
|
|
|
61 |
the area where possible multiple classes with the same name could
|
|
|
62 |
cause confusion. A later revision may include consistency checks.
|
|
|
63 |
}
|
|
|
64 |
\value{
|
|
|
65 |
As described, a matrix with entries 0 or 1, non-zero values
|
|
|
66 |
indicating that the class corresponding to the column is a direct
|
|
|
67 |
superclass of the class corresponding to the row. The row and
|
|
|
68 |
column names are the class names (without package slot).
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
\seealso{
|
|
|
73 |
\code{\link{extends}} and \linkS4class{classRepresentation} for the underlying information from the class
|
|
|
74 |
definition.
|
|
|
75 |
}
|
|
|
76 |
\examples{
|
|
|
77 |
|
| 56287 |
ripley |
78 |
## the super- and subclasses of "standardGeneric"
|
|
|
79 |
## and "derivedDefaultMethod"
|
| 48079 |
jmc |
80 |
am <- classesToAM(list(class(show), class(getMethod(show))), TRUE)
|
|
|
81 |
am
|
|
|
82 |
|
|
|
83 |
\dontrun{
|
|
|
84 |
## the following function depends on the Bioconductor package Rgraphviz
|
|
|
85 |
plotInheritance <- function(classes, subclasses = FALSE, ...) {
|
|
|
86 |
if(!require("Rgraphviz", quietly=TRUE))
|
|
|
87 |
stop("Only implemented if Rgraphviz is available")
|
|
|
88 |
mm <- classesToAM(classes, subclasses)
|
|
|
89 |
classes <- rownames(mm); rownames(mm) <- colnames(mm)
|
|
|
90 |
graph <- new("graphAM", mm, "directed", ...)
|
|
|
91 |
plot(graph)
|
|
|
92 |
cat("Key:\n", paste(abbreviate(classes), " = ", classes, ", ",
|
|
|
93 |
sep = ""), sep = "", fill = TRUE)
|
|
|
94 |
invisible(graph)
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
## The plot of the class inheritance of the package "graph"
|
|
|
98 |
require(graph)
|
|
|
99 |
plotInheritance(getClasses("package:graph"))
|
|
|
100 |
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
\keyword{classes}
|
|
|
105 |
\keyword{programming}
|