title: All Paths Between 2 vertexes in R
body: <p>I use igraph.</p>
  
  <p>I want yo find all the possible paths between 2 nodes.</p>
  
  <p>For the moment, there doesn't seem to exist any function to find all the paths between 2 nodes in igraph</p>
  
  <p>I found this subject that gives code in python:
  <a href="https://stackoverflow.com/questions/3971876/all-possible-paths-from-one-node-to-another-in-a-directed-tree-igraph">All possible paths from one node to another in a directed tree (igraph)</a></p>
  
  <p>I tried to port it to R but I have some little problems. It gives me the error:</p>
  
  <pre><code>Error of for (newpath in newpaths) { : 
    for() loop sequence incorrect
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>find_all_paths &lt;- function(graph, start, end, mypath=vector()) {
    mypath = append(mypath, start)
  
    if (start == end) {
      return(mypath)
    }
  
    paths = list()
  
    for (node in graph[[start]][[1]]) {
       if (!(node %in% mypath)){
        newpaths &lt;- find_all_paths(graph, node, end, mypath)
        for (newpath in newpaths){
          paths &lt;- append(paths, newpath)
        }
       }
    }
    return(paths)
  }
  
  test &lt;- find_all_paths(graph, farth[1], farth[2])
  </code></pre>
  
  <p>Here is a dummy code taken from the igrah package, from which to get a sample graph and nodes:</p>
  
  <pre><code>actors &lt;- data.frame(name=c("Alice", "Bob", "Cecil", "David",
                               "Esmeralda"),
                        age=c(48,33,45,34,21),
                        gender=c("F","M","F","M","F"))
  relations &lt;- data.frame(from=c("Bob", "Cecil", "Cecil", "David",
                                  "David", "Esmeralda"),
                           to=c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice"),
                           same.dept=c(FALSE,FALSE,TRUE,FALSE,FALSE,TRUE),
                           friendship=c(4,5,5,2,1,1), advice=c(4,5,5,4,2,3))
  g &lt;- graph.data.frame(relations, directed=FALSE, vertices=actors)
  
  farth &lt;- farthest.nodes(g)
  
  test &lt;- find_all_paths(graph, farth[1], farth[2])
  </code></pre>
  
  <p>thanks!</p>
  
  <p>If anyone sees where the problem, that would be of great help...</p>
  
  <p>Mathieu</p>