| Title: | Construct Graphs of S4 Class Hierarchies |
|---|---|
| Description: | Construct directed graphs of S4 class hierarchies and visualize them. In general, these graphs typically are DAGs (directed acyclic graphs), often simple trees in practice. |
| Authors: | Martin Maechler [cre, aut] (Partly based on code from Robert Gentleman, <https://orcid.org/0000-0002-8685-9910>) |
| Maintainer: | Martin Maechler <[email protected]> |
| License: | GPL |
| Version: | 0.7-7 |
| Built: | 2026-05-24 09:55:15 UTC |
| Source: | https://github.com/cran/classGraph |
The package classGraph is package using graph and graph visualization methods to visualize inheritance graphs of S4 classes.
| Package: | classGraph |
| Type: | Package |
| Title: | Construct Graphs of S4 Class Hierarchies |
| Version: | 0.7-7 |
| Authors@R: | person("Martin", "Maechler", role = c("cre", "aut"), email = "[email protected]", comment = c("Partly based on code from Robert Gentleman", ORCID = "0000-0002-8685-9910")) |
| Depends: | methods |
| Imports: | graphics, stats, utils, graph, Rgraphviz |
| Suggests: | Matrix |
| Description: | Construct directed graphs of S4 class hierarchies and visualize them. In general, these graphs typically are DAGs (directed acyclic graphs), often simple trees in practice. |
| License: | GPL |
| NeedsCompilation: | no |
| Packaged: | 2025-04-29 09:39:26 UTC; maechler |
| Author: | Martin Maechler [cre, aut] (Partly based on code from Robert Gentleman, <https://orcid.org/0000-0002-8685-9910>) |
| Maintainer: | Martin Maechler <[email protected]> |
| Config/pak/sysreqs: | zlib1g-dev |
| Repository: | https://mmaechler.r-universe.dev |
| Date/Publication: | 2025-04-29 11:40:06 UTC |
| RemoteUrl: | https://github.com/cran/classGraph |
| RemoteRef: | HEAD |
| RemoteSha: | f723fc6a6e39d5e1022c2da565db4929dfc39e2f |
Index of help topics:
bGraph Create a "Branch Graph" (Simple Tree with Root
and Leaves)
class2Graph Build the Graph of Super Classes from an S4
Class Definition
classGraph-package The R Package 'classGraph'
classTree builds a directed graph, typically a tree from
a class Object
mRagraph Construct a Laid-Out Graph for Plotting
numOutEdges For each Node of a Directed Graph give the
Number Outgoing Edges
plotRag Plot an Ragraph (using Rgraphviz)
subClasses All Subclasses of a Given S4 Class
superClasses List of Super Classes of a Given S4 Class
Martin Maechler
classTree() is the main function of this package.
Create a “Branch Graph”, i.e., a simple tree with root and
(simple) branches or leaves.
bGraph(n, root = "Mom", leaves = paste(l.prefix, seq(length = n), sep = ""), l.prefix = "D", weights = NULL, mode = c("undirected", "directed"))bGraph(n, root = "Mom", leaves = paste(l.prefix, seq(length = n), sep = ""), l.prefix = "D", weights = NULL, mode = c("undirected", "directed"))
n |
integer specifying the number of leave branches. |
root |
the node on which to root the tree. |
leaves |
the nodes to be used as leaves. |
l.prefix |
a string specifying ..... |
weights |
....... |
mode |
string indicating which mode is to be used. |
a graph object of class graphNEL.
Martin Maechler, Aug.2005
class graphNEL;
ftM2graphNEL.
require("graph") ## Using package 'graph' => plot() method (via package 'Rgraphviz'): (bg7 <- bGraph(7)) # 8 nodes {Mom, D1..D7}; 7 edges plot(bg7) # draws the graph (bgD3 <- bGraph(3, mode="directed")) plot(bgD3) # directed: using arrows (bgw2 <- bGraph(2, weights = c(10,1))) plot(bgw2) # {maybe use lwd for weights in the future?} if(require("Matrix")) show(as(bgw2, "sparseMatrix")) # shows the weightsrequire("graph") ## Using package 'graph' => plot() method (via package 'Rgraphviz'): (bg7 <- bGraph(7)) # 8 nodes {Mom, D1..D7}; 7 edges plot(bg7) # draws the graph (bgD3 <- bGraph(3, mode="directed")) plot(bgD3) # directed: using arrows (bgw2 <- bGraph(2, weights = c(10,1))) plot(bgw2) # {maybe use lwd for weights in the future?} if(require("Matrix")) show(as(bgw2, "sparseMatrix")) # shows the weights
From an S4 class definition class, computes the graph of all
super classes, i.e., of all classes that class extends.
class2Graph(class, fullNames = TRUE, simpleOnly = FALSE, bottomUp = FALSE, package = class@package)class2Graph(class, fullNames = TRUE, simpleOnly = FALSE, bottomUp = FALSE, package = class@package)
class |
class name |
fullNames |
logical indicating if full name should be applied.... |
simpleOnly |
logical, simply passed to
|
bottomUp |
logical indicating the direction of the graph. |
package |
package where the super classes should be gotten from. |
an R object inheriting from class graph.
Robert Gentleman (original code) and Martin Maechler
classTree which builds the graph of all
subclasses.
require("graph") cg <- class2Graph("graphNEL") # simple : graphNEL |-> graph plot(cg) if(require("Matrix")) { cg2 <- class2Graph("dgCMatrix") as(cg2, "sparseMatrix") plot(cg2) ## alternative: don't show the initial "Matrix:" cg2. <- class2Graph("dgCMatrix", fullNames=FALSE) plot(cg2.) ## 'simpleOnly' does not change anything here : stopifnot(identical(cg2., class2Graph("dgCMatrix", fullNames=FALSE, simpleOnly = TRUE))) ## very simple, since "sparseMatrix" only extends "Matrix" : cg3 <- class2Graph("sparseMatrix") plot(cg3) }require("graph") cg <- class2Graph("graphNEL") # simple : graphNEL |-> graph plot(cg) if(require("Matrix")) { cg2 <- class2Graph("dgCMatrix") as(cg2, "sparseMatrix") plot(cg2) ## alternative: don't show the initial "Matrix:" cg2. <- class2Graph("dgCMatrix", fullNames=FALSE) plot(cg2.) ## 'simpleOnly' does not change anything here : stopifnot(identical(cg2., class2Graph("dgCMatrix", fullNames=FALSE, simpleOnly = TRUE))) ## very simple, since "sparseMatrix" only extends "Matrix" : cg3 <- class2Graph("sparseMatrix") plot(cg3) }
From an S4 class, by investigating all subclasses, a inheritance graph is built, a directed graph, often a tree.
classTree(Cl, all = FALSE, ...)classTree(Cl, all = FALSE, ...)
Cl |
class name ... |
all |
logical indicating if all instead of just direct sub-classes should be used. |
... |
.... |
an R object inheriting from class graph.
Martin Maechler
class2Graph, ...
## Using classes and methods from package 'graph' : trGclass <- classTree("graph") as(trGclass, "matrix") plot(trGclass) # using package 'Rgraphviz'## Using classes and methods from package 'graph' : trGclass <- classTree("graph") as(trGclass, "matrix") plot(trGclass) # using package 'Rgraphviz'
My constructor of an Ragraph
object, a kind of “laid-out” graph, from package
Rgraphviz. This allows more customization in plotting than just
calling plot(gr, ...) for a
graph object from package
graph.
mRagraph(gr, lType, fixedsize = FALSE, fill = c("lightblue", "gray90"), color = c("blue3", "gray60"), labcol = c("blue3", "green4", "purple"))mRagraph(gr, lType, fixedsize = FALSE, fill = c("lightblue", "gray90"), color = c("blue3", "gray60"), labcol = c("blue3", "green4", "purple"))
gr |
an R object of class |
lType |
a string specifying the layout type,
see |
fixedsize |
logical indicating if the ellipses should all get the same size – or should rather adapt to the situation. |
fill |
character vector of length 2.... |
color |
character vector of length 2.... |
labcol |
vector of labels to be used .... |
an object of class Ragraph,
produced by an appropriate call to agopen.
Martin Maechler
the customized plotting function plotRag.
if(require("Matrix")) { trMatrix <- classTree("Matrix") trMatrix RtrM <- mRagraph(trMatrix) RtrM # (the show method will hopefully improve) str(RtrM, max=2) # shows a bit more plot(RtrM)# 'graph' method -> using 'Rgraphviz' package }if(require("Matrix")) { trMatrix <- classTree("Matrix") trMatrix RtrM <- mRagraph(trMatrix) RtrM # (the show method will hopefully improve) str(RtrM, max=2) # shows a bit more plot(RtrM)# 'graph' method -> using 'Rgraphviz' package }
In a directed or undirected graph, for each node count the number of edges “leaving” that nodes.
numOutEdges(g)numOutEdges(g)
g |
an R object of class |
an integer vector the same length as
nodes(g) giving the number of edges that “go
out” from each node.
Martin Maechler
edgeL on which this function is built, and
leaves, both from package graph.
## Simplistic leaves() definition for *directed graphs* : ## { compare with graph::leaves() } is.leaf <- function(g) numOutEdges(g) == 0 ## (also exists hiddenly..) Leaves <- function(g) graph::nodes(g)[is.leaf(g)] Leaves(bGraph(4, mode = "directed"))## Simplistic leaves() definition for *directed graphs* : ## { compare with graph::leaves() } is.leaf <- function(g) numOutEdges(g) == 0 ## (also exists hiddenly..) Leaves <- function(g) graph::nodes(g)[is.leaf(g)] Leaves(bGraph(4, mode = "directed"))
Plot an Ragraph
object (a kind of “laid-out” graph, from package
Rgraphviz). This the simply uses the plot method
from package Rgraphviz (i.e., selectMethod(plot, "Ragraph"))
and additionally adds a “footnote”-like subtitle.
plotRag(ragr, sub, subArgs = .optRagargs(), ...) .optRagargs(side = 1, adj = 0.05, cex = 0.75, line = 3)plotRag(ragr, sub, subArgs = .optRagargs(), ...) .optRagargs(side = 1, adj = 0.05, cex = 0.75, line = 3)
ragr |
an object of class
|
sub |
a “footnote” or subtitle to be added to
|
subArgs |
a |
... |
further arguments passed to |
side, adj, cex, line
|
arguments passed to |
Martin Maechler
if(require("Matrix")) { trMatrix <- classTree("Matrix") trMatrix RtrM <- mRagraph(trMatrix) RtrM # (the show method will hopefully improve) str(RtrM, max=2) # shows a bit more plot(RtrM) ## almost the same as plotRag(RtrM, subArgs=.optRagargs(adj = 0.5)) ## which just gives "<n> nodes with <m> edges" }if(require("Matrix")) { trMatrix <- classTree("Matrix") trMatrix RtrM <- mRagraph(trMatrix) RtrM # (the show method will hopefully improve) str(RtrM, max=2) # shows a bit more plot(RtrM) ## almost the same as plotRag(RtrM, subArgs=.optRagargs(adj = 0.5)) ## which just gives "<n> nodes with <m> edges" }
Retugn all subclasses of a given S4 class; either only the direct sub
classes are also those “further away” (distance ).
subClasses(Cl, directOnly = TRUE, complete = TRUE, ...)subClasses(Cl, directOnly = TRUE, complete = TRUE, ...)
Cl |
a class representation or a class name ( |
directOnly |
logical indicating if you direct subclasses
are desired (or also the ones with distance |
complete |
logical,.. as in.... |
... |
........ |
a character vector of class names.
Martin Maechler
superClasses; Classes in
general.
subClasses("graph") # -> the direct ones subClasses("graph", directOnly = FALSE) # the same: has only direct subclasses if(require("Matrix")) { print( subClasses("sparseMatrix") ) print( subClasses("sparseMatrix", directOnly = FALSE) )# much more }subClasses("graph") # -> the direct ones subClasses("graph", directOnly = FALSE) # the same: has only direct subclasses if(require("Matrix")) { print( subClasses("sparseMatrix") ) print( subClasses("sparseMatrix", directOnly = FALSE) )# much more }
Give a list of all super classes of a specific
S4 class (definition).
superClasses(x)superClasses(x)
x |
a class representation as returned by
|
a list of length-1 character strings, typically with a
"package" attribute each.
Robert Gentleman and Martin Maechler
subClasses, ...
superClasses(getClassDef("graphNEL")) if(require("Matrix")) { scL <- superClasses(getClassDef("dgeMatrix")) str(scL) # a list of two } # 'Matrix'superClasses(getClassDef("graphNEL")) if(require("Matrix")) { scL <- superClasses(getClassDef("dgeMatrix")) str(scL) # a list of two } # 'Matrix'