[R] igraph function "graph.bfs" unavailable
David Marx
dmarx at SOUNDEXCHANGE.COM
Wed Jul 11 16:36:05 CEST 2012
Hi,
I've installed the igraph package and have been otherwise using it successfully, but when I try to use graph.bfs I get the error:
could not find function "graph.bfs"
Moreover, I don't seem to have the documentation installed either. (per ?graph.bfs and ??graph.bfs).
I'm using RStudio v0.95.262 on windows 7. Below is the info for my R build:
R version 2.14.0 (2011-10-31)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-mingw32/x64 (64-bit)
If for some reason this algorithm really is just unavailable, maybe someone can come up with another way to solve my problem. I need a function that builds subgraphs up to a limited distance from an input root node. I feel like this is a common enough task that there's probably an easier way to do it, but I'm still learning what tools are available to me in igraph and built my own solution. The code below was tested on a machine that didn't have issues with graph.bfs (I changed some variable names for the purpose of this post, so maybe I broke something):
isolated.subgraph <- function(main.graph, node.name, bfs.dist=2){
# Get vertex id for root node from input graph
node.vid <- V(main.graph)[nodeName==node.name][[1]]
# Traverse graph using breadth-first search
# to distance of 2 from root
node.bfs <- graph.bfs(main.graph, root=node.vid
,callback=function(graph, data, extra){data['dist'] == bfs.dist}
)
# Isolate pertinent subgraph from nodes in node.bfs.
# Need to trim out NaN vertices from node.bfs
node.g <- induced.subgraph(all, node.bfs$order[which(!is.na(node.bfs$order))])
return(node.g)
}
Thanks,
David Marx
Please note our office has moved:
David Marx | Data Analyst Specialist, Claims Dept | SoundExchange, Inc.
733 10th Street, NW | 10th Floor | Washington, DC 20001
P: 202.640.5858 | F: 202.640.5859 | info at soundexchange.com
www.SoundExchange.com | Facebook | Twitter| YouTube
More information about the R-help
mailing list