buildNodeList: A function to build lists of node and edge objects


These functions can be used to generate lists of pNode and pEdge objects from an object of class graph. These lists can then be sent to Graphviz to initialize and layout the graph for plotting.


buildNodeList(graph, nodeAttrs = list(), subGList=list(), defAttrs=list())
buildEdgeList(graph, recipEdges=c("combined", "distinct"),
              edgeAttrs = list(), subGList=list(), defAttrs=list())



An object of class graph


A list of attributes for specific nodes


A list of attributes for specific edges


A list of any subgraphs to be used in Graphviz


How to deal with reciprocated edges


A list of attributes used to specify defaults.


These functions will take either the nodes or the edges of the specified graph and generate a list of either pNode or pEdge objects.

The recipEdges argument can be used to specify how to handle reciprocal edges. The default value, combined will combine any reciprocated edges into a single edge (and if the graph is directed, will by default place an arrowhead on both ends of the edge), while the other option is distinct which will draw to separate edges. Note that in the case of an undirected graph, every edge of a graphNEL is going to be reciprocal due to implementation issues.

The nodeAttrs and edgeAttrs attribute lists are to be used for cases where one wants to set an attribute on a node or an edge that is not the default. In both cases, these are lists with the names of the elements corresponding to a particular attribute and the elements containing a named vector - the names of the vector are names of either node or edge objects and the values in the vector are the values for this attribute.

Note that with the edgeAttrs list, the name of the edges are in a particular format where an edge between x and y is named x~y. Note that even in an undirected graph that x~y is not the same as y~x - the name must be in the same order that the edge was defined as having.

The subGraph argument can be used to specify a list of subgraphs that one wants to use for this plot. The buildXXXList functions will determine if a particular node or edge is in one of the subgraphs and note that in the object.

The defAttrs list is a list used to specify any default values that one wishes to use. The element names corresponde to the attribute and the value is the default for that particular attribute.

If there is no default specified in defAttrs for an attribute declared in nodeAttrs or edgeAttrs, then the latter must have a value for every node or edge in the graph. Otherwise, if a default is supplied, that value is used for any node or edge not explicitly defined for a particular attribute.


A list of class pNode or pEdge objects.


Jeff Gentry

See Also

agopen, plot.graph, pNode,pEdge


   V <- letters[1:10]
   M <- 1:4
   g1 <- randomGraph(V, M, .2)

   z <- buildEdgeList(g1)
   x <- buildNodeList(g1)

Questions? Problems? Suggestions? or email at

All documentation is copyright its authors; we didn't write any of that.