Last active
August 31, 2022 15:52
-
-
Save johnrc/faaa796e4b1ac53b7848 to your computer and use it in GitHub Desktop.
Print dependency tree for R package
This file contains hidden or 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
## function getDependencyTree() | |
# Only parameter that's required is the package you want a dependency tree for | |
getDependencyTree <- function(pack, i = -1, depLevel = c("Depends", "Imports", "LinkingTo"), availablePackages = available.packages()) { | |
if(i == -1) cat(pack, "\n") | |
i <- i + 1 | |
packages <- unlist(tools::package_dependencies(pack, availablePackages, which = depLevel)) | |
for(pkg in packages) { | |
for(n in 0:i) { | |
cat(" ") | |
} | |
cat("|", pkg, "\n") | |
getDependencyTree(pkg, i, depLevel) | |
} | |
} ## end function getDependencyTree() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Runs much faster if you change line 12 to this: