-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgraph-igraph.R
40 lines (29 loc) · 1.03 KB
/
graph-igraph.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#' @rdname appr
#' @export
appr.igraph <- function(graph, seeds, ...) {
if (!requireNamespace("igraph", quietly = TRUE))
stop("`igraph` package must be installed to use igraphs.", call. = FALSE)
if (is.null(igraph::V(graph)$name))
igraph::V(graph)$name <- as.character(1:igraph::gorder(graph))
appr.abstract_graph(graph = graph, seeds = seeds, ...)
}
check.igraph <- function(graph, nodes) {
node_names <- names(igraph::V(graph))
nodes_in_graph <- nodes[nodes %in% node_names]
nodes_in_graph[igraph::degree(graph, v = nodes_in_graph, mode = "out") > 0]
}
node_degrees.igraph <- function(graph, nodes) {
list(
in_degree = igraph::degree(graph, v = nodes, mode = "in"),
out_degree = igraph::degree(graph, v = nodes, mode = "out")
)
}
# character list of neighboring nodes
# treat directed vs undirected differently?
neighborhood.igraph <- function(graph, node) {
int_node_list <- igraph::ego(
graph, nodes = node, mode = "out", mindist = 1
)
nodes <- int_node_list[[1]]
igraph::V(graph)$name[nodes]
}