Skip to content

Commit

Permalink
test igraph behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Dec 3, 2024
1 parent 06def26 commit f872e3a
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions R/utils_igraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,36 @@ nbhd_vertices <- function(graph, vertices, mode, order) {
vertices
}

targets_adjacent_vertices <- function(graph, v, mode) {
targets_adjacent_vertices <- function(graph, v, mode, offset = NULL) {
opt <- igraph::igraph_opt("return.vs.es")
on.exit(igraph::igraph_options(return.vs.es = opt))
igraph::igraph_options(return.vs.es = FALSE)
index <- igraph::adjacent_vertices(graph = graph, v = v, mode = mode)
index <- unlist(index, use.names = FALSE)
index <- unique(index)
if (is.null(igraph_version_offset$offset)) {
igraph_version_offset$offset <- as.integer(
utils::compareVersion(
a = as.character(packageVersion("igraph")),
b = "2.1.2"
) < 0L
)
igraph::V(graph)$name[index + get_igraph_offset()]
}

get_igraph_offset <- function() {
if (!is.null(igraph_offset$offset)) {
return(igraph_offset$offset)
}
igraph::V(graph)$name[index + igraph_version_offset$offset]
opt <- igraph::igraph_opt("return.vs.es")
on.exit(igraph::igraph_options(return.vs.es = opt))
igraph::igraph_options(return.vs.es = FALSE)
test_graph <- igraph::make_graph(edges = c("a", "b"))
adjacent <- igraph::adjacent_vertices(
graph = test_graph,
v = "a",
mode = "out"
)
adjacent <- as.integer(adjacent)
offset <- 2L - adjacent
igraph_offset$offset <- offset
offset
}

igraph_version_offset <- new.env(parent = emptyenv())
igraph_offset <- new.env(parent = emptyenv())

igraph_leaves <- function(igraph) {
is_leaf <- igraph::degree(igraph, mode = "in") == 0L
Expand Down

0 comments on commit f872e3a

Please sign in to comment.