File: subgraph.R

package info (click to toggle)
r-cran-lava 1.8.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,816 kB
  • sloc: sh: 13; makefile: 2
file content (18 lines) | stat: -rw-r--r-- 613 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
subgraph <- function(g,from,to,Tree=new("graphNEL",node=c(to,from),edgemode="directed"),...) {
    adjnodes <- graph::adj(g,from)[[1]]
    if (length(adjnodes)==0)
        return(Tree)
    for (v in adjnodes) {
        if (v==to) {
            Tree <- graph::addEdge(from, v, Tree)
        }
        re1 <- graph::acc(g,v)[[1]] ## Reachable nodes from v
        if ((to %in% names(re1)[re1>0])) {
            if (!(v %in% graph::nodes(Tree)))
                Tree <- graph::addNode(v,Tree)
            Tree <- graph::addEdge(from, v, Tree)
            Tree <- path(g,v,to,Tree)
        }
    }
    return(Tree)
}