library("gbutils")
adjacencyOfClasses computes a graph representation of the
dependencies of S4 classes defined in one or more packages (as
specified by argument package) and returns a list. The
contents of the list returned by adjacencyOfClasses depend on
argument result. Partial matching is used for the value of
argument result, e.g., "adj" is equivalent to
"adjacencyMatrix".
If externalSubclasses = FALSE, the default, subclasses defined
outside the requested packages are excluded. This is typically what
the user will be looking for. To get a complete tree, set
externalSubclasses to TRUE.
The S4 classes are represented by the vertices of the graph.
Component "vertices" of the result gives them as a character
vector. References below to the \(i\)th class or vertex
correspond to the order in this vector. No attempt is made to arrange
the vertices in a particular order. An empty list is returned if this
vector is empty.
If result is missing or "default", the edges of the
graph are represented by a character vector. Each edge is represented
by a string with an arrow "->" from a superclass to a
subclass. Here is an example that shows that this package defines one
class, which is a subclass of "list":
adjacencyOfClasses("gbutils")
This illustrates the effect of argument "externalSubclasses":
adjacencyOfClasses("gbutils", externalSubclasses = TRUE)
The edge, "vector -> list" was omitted in the previous example since
this relationship is defined elsewhere. This resulted in class
"vector" being dropped also from the vertices, since it is not
defined in "gbutils" and none of the remaining edges contains
it.
If result is "matrixOfPairs", the edges of the
graph are represented by a character matrix with two columns, where each row
represents an edge from the element in the first column to the element
in the second. In this example there is one edge, so the matrix
contains one row:
adjacencyOfClasses("gbutils", result = "matrixOfPairs")
If result is "adjacencyMatrix", the adjacency matrix of
the graph is in component "AM" of the returned list. Element \((i,j)\) of
this matrix is equal to one, if the \(j\)th class is a superclass
to the \(i\)th. In other words, the \(j\)th column gives the
superclasses of the \(i\)th class. Here the element in position
(1,2) is non-zero, so "list" is the superclass of "objectPad":
adjacencyOfClasses("gbutils", result = "adjacencyMatrix")
Note that including the vertices in the result is not redundant, since
some may not be in any edge. This can happen if a class does not
have any superclasses and subclasses.
As described above the result is not converted to a graph object but
it can be fed to functions provided by a number of R packages.
An additional option is to use argument Wolfram. If
Wolfram is TRUE, a suitable Mathematica command is
printed. It can be evaluated in a Mathematica session (e.g., by
copy/paste) to produce a graphical representation of the graph and/or
be manipulated further by it. This feature is a side effect, the
return value of adjacencyOfClasses is as controlled by the
other arguments. For example, the return value below is as without
argument "Wolfram" but, in addition, the printed line defines a
Wolfram language graph in terms of its vertices and edges:
adjacencyOfClasses("gbutils", Wolfram = TRUE)
Setting result = "adjacencyMatrix" in the last R command
exports the graph in terms of its adjacency matrix:
adjacencyOfClasses("gbutils", Wolfram = TRUE, result = "adjacencyMatrix")