Skip to content

Instantly share code, notes, and snippets.

@chainsawriot
Last active February 16, 2023 16:27
Show Gist options
  • Save chainsawriot/3d7ef383230e6c3cf15a289dba535c68 to your computer and use it in GitHub Desktop.
Save chainsawriot/3d7ef383230e6c3cf15a289dba535c68 to your computer and use it in GitHub Desktop.
require(rang)
require(purrr)
require(igraph)
convert_edgelist <- function(x) {
output <- data.frame(x = x$pkg, y = rang:::.extract_queryable_dependencies(x$original, x$no_enhances, x$no_suggests))
for (dep in x$deps) {
if (!rang:::.is_terminal_node(dep, x$no_enhances)) {
el <- data.frame(x = unique(dep$x_pkgref), y = rang:::.extract_queryable_dependencies(dep, x$no_enhances, x$no_suggests))
output <- rbind(output, el)
}
}
output
}
graph <- resolve(c("REDCapExporter", "redcapAPI", "REDCapDM", "ReviewR", "rccola"))
el <- unique(purrr::map_dfr(graph$ranglets, convert_edgelist))
graph_as_igraph <- graph_from_edgelist(as.matrix(el))
sort(degree(graph_as_igraph, mode = "in"))
## shallow dependecies
sort(degree(graph_from_edgelist(as.matrix(el[el$x %in% rang:::.normalize_pkgs(c("REDCapExporter", "redcapAPI", "REDCapDM", "ReviewR", "rccola")), ])), mode = "in"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment