A topological ordering of a directed graph is a linear ordering of its vertices such that, for every edge (u>v), u comes before v in the ordering. A topological ordering is possible if and only if the graph has no directed cycles, that is, if it is a directed acyclic graph (DAG). Any DAG has at least one topological ordering. Can hence be used for checking if a graph is a DAG.
1 2 3 4 5 6 
object 
An graph represented either as a 
index 
If FALSE, an ordering is returned if it exists and

amat 
Adjacency matrix. 
If FALSE, an ordering is returned if it exists and
character(0)
otherwise. If TRUE, the index of the
variables in an adjacency matrix is returned and 1
otherwise.
The workhorse is the topoSortMAT
function
which takes an adjacency matrix as input
Søren Højsgaard, sorenh@math.aau.dk
dag
, ug
1 2 3 4 5 6 7 
Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
All documentation is copyright its authors; we didn't write any of that.