folder <- system.file("example_data/Zeeguu-Ecosystem/Zeeguu-API/zeeguu_core", package = "Rchitecture")
files <- list.files(folder, recursive = TRUE, full.names = TRUE) %>%
stringr::str_extract(".*\\.py$") %>%
na.omit()
edges <- map(files, import_from)
edge_table <- map_df(edges, transpose)
node_table <- tibble::tibble(
id = unique(c(edge_table$to, edge_table$from)),
label= str_remove(id, paste0(folder, "/")),
folder = folder,
subfolder = str_remove(label, "[^/]+$")
) %>%
mutate_at(vars(-id),
~str_replace_all(.x, "/+", "/")
)
library(tidygraph)
graph <- tbl_graph(
nodes = node_table,
edges = edge_table
) %>%
activate("nodes") %>%
mutate(graph_component = group_components()) # numeric for connected components
library(ggraph)
ggraph(graph, layout = "igraph", algorithm = "fr") +
geom_edge_diagonal() +
geom_node_point(aes(color = subfolder)) +
scale_color_brewer(type = "qual") +
theme_void()
subgraphs that have imports across subfolders of zeeguu core.
as_tibble(graph) %>% group_by(graph_component) %>% summarise(n_distinct(subfolder))