Skip to content

Instantly share code, notes, and snippets.

@johnrc
Last active August 31, 2022 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnrc/faaa796e4b1ac53b7848 to your computer and use it in GitHub Desktop.
Save johnrc/faaa796e4b1ac53b7848 to your computer and use it in GitHub Desktop.
Print dependency tree for R package
## 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()
@kenahoo
Copy link

kenahoo commented Mar 6, 2019

Runs much faster if you change line 12 to this:

getDependencyTree(pkg, i, depLevel, availablePackages)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment