Rev 49233 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{classesToAM}\alias{classesToAM}\title{Compute an Adjacency Matrix for Superclasses of one or more Class Definitions}\description{Given a vector of class names or a list of class definitions, thefunction returns an adjacency matrix of the superclasses of theseclasses; that is, a matrix with class names as the row and columnnames and with element [i, j] being 1 if the class in column j is adirect superclass of the class in row i, and 0 otherwise.The matrix has the information implied by the \code{contains} slot ofthe class definitions, but in a form that is often more convenient forfurther analysis; for example, an adjacency matrix is used in packagesand other software to construct graph representations of relationships.}\usage{classesToAM(classes, includeSubclasses = FALSE,abbreviate = 2)}\arguments{\item{classes}{Either a character vector of class names or a list, whoseelements can be either class names or class definitions. Thelist is convenient, for example, to include the package slot forthe class name. See the examples.}\item{includeSubclasses}{A logical flag; if \code{TRUE}, then the matrix will include allthe known subclasses of the specified classes as well as thesuperclasses. The argument can also be a logical vector of thesame length as \code{classes}, to include subclasses for somebut not all the classes.}\item{abbreviate}{Control of the abbreviation of the row and/or column labels ofthe matrix returned: values 0, 1, 2, or 3 abbreviate neither,rows, columns or both. The default, 2, is useful for printingthe matrix, since class names tend to be more than onecharacter long, making for spread-out printing. Values of 0or 3 would be appropriate for making a graph (3 avoids thetendency of some graph plotting software to produce labels inminuscule font size).}}\details{For each of the classes, the calculation gets all the superclassnames from the class definition, and finds the edges in those classes'definitions; that is, all the superclasses at distance 1. Thecorresponding elements of the adjacency matrix are set to 1.The adjacency matrices for the individual class definitions aremerged. Note two possible kinds of inconsistency, neither of whichshould cause problems except possibly with identically named classes fromdifferent packages. Edges are computed from each superclassdefinition, so that information overrides a possible inference fromextension elements with distance > 1 (and it should). Whenmatrices from successive classes in the argument are merged, thecomputations do not currently check for inconsistencies---this isthe area where possible multiple classes with the same name couldcause confusion. A later revision may include consistency checks.}\value{As described, a matrix with entries 0 or 1, non-zero valuesindicating that the class corresponding to the column is a directsuperclass of the class corresponding to the row. The row andcolumn names are the class names (without package slot).}\seealso{\code{\link{extends}} and \linkS4class{classRepresentation} for the underlying information from the classdefinition.}\examples{## the super- and subclasses of "standardGeneric" and "derivedDefaultMethod"am <- classesToAM(list(class(show), class(getMethod(show))), TRUE)am\dontrun{## the following function depends on the Bioconductor package RgraphvizplotInheritance <- function(classes, subclasses = FALSE, ...) {if(!require("Rgraphviz", quietly=TRUE))stop("Only implemented if Rgraphviz is available")mm <- classesToAM(classes, subclasses)classes <- rownames(mm); rownames(mm) <- colnames(mm)graph <- new("graphAM", mm, "directed", ...)plot(graph)cat("Key:\n", paste(abbreviate(classes), " = ", classes, ", ",sep = ""), sep = "", fill = TRUE)invisible(graph)}## The plot of the class inheritance of the package "graph"require(graph)plotInheritance(getClasses("package:graph"))}}\keyword{classes}\keyword{programming}