Last active
November 16, 2023 10:49
-
-
Save jokergoo/0c27721edb33c2a351fef719e64be05a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = sessionInfo() | |
base_pkgs = x$basePkgs | |
other_pkgs = sapply(x$otherPkgs, function(x)x$Package) | |
loaded_pkgs = sapply(x$loadedOnly, function(x)x$Package) | |
db = reformat_db(installed.packages()) | |
mat = matrix(nrow = 0, ncol = 3) | |
for(pkg in other_pkgs) { | |
mat = rbind(mat, db$package_dependencies(pkg, recursive = TRUE, which = "strong")) | |
} | |
mat = unique(mat) | |
mat = mat[!mat[, 1] %in% pkgndep:::BASE_PKGS | mat[, 2] %in% pkgndep:::BASE_PKGS, , drop = FALSE] | |
all_pkgs = c(other_pkgs, loaded_pkgs) | |
mat = mat[mat[, 1] %in% all_pkgs & mat[, 2] %in% all_pkgs, , drop = FALSE] | |
all_nodes = unique(c(mat[, 1], mat[, 2], other_pkgs, loaded_pkgs)) | |
node_col = rep("black", length(all_nodes)) | |
node_col[all_nodes %in% other_pkgs] = "red" | |
node_col[all_nodes %in% loaded_pkgs] = "blue" | |
nodes = qq(" \"@{all_nodes}\" [color=\"@{node_col}\"];", collapse = FALSE) | |
dep_col = c(2, 4, 3) | |
dep_col = rgb(t(col2rgb(dep_col)), max = 255) | |
names(dep_col) = c("Depends", "Imports", "LinkingTo") | |
edges = qq(" \"@{mat[, 1]}\" -> \"@{mat[, 2]}\" [color=\"@{dep_col[mat[, 3]]}\"];", collapse = FALSE) | |
dot = paste( | |
c("digraph {", | |
" nodesep=0.05", | |
" rankdir=LR;", | |
" graph [overlap = true];", | |
" node[shape = box];", | |
nodes, | |
edges, | |
"}"), | |
collapse = "\n" | |
) | |
DiagrammeR::grViz(dot) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment