Last active
April 3, 2017 16:25
-
-
Save vankesteren/3e637e7ada4052f0d173736d6d05f84e 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
listDependencies <- function(pkgs){ | |
# Recursively looks through package dependencies (depends & imports) of a list of packages | |
# Argument: a character vector of package names | |
pack <- available.packages() | |
pnames <- pack[,1] | |
depmat <- matrix(ncol=3) | |
while (TRUE){ | |
imports <- tools::package_dependencies(pack[pkgs[pkgs %in% pnames],], which = "Imports") | |
depends <- tools::package_dependencies(pack[pkgs[pkgs %in% pnames],], which = "Depends") | |
for (i in imports){ | |
if (is.matrix(i)) depmat <- rbind(depmat,i) | |
} | |
for (d in depends){ | |
if (is.matrix(d)) depmat <- rbind(depmat,d) | |
} | |
if (all(pkgs %in% unique(depmat[-1,1]))){ | |
break | |
} | |
pkgs <- unique(depmat[-1,1]) | |
depmat <- unique(depmat) | |
} | |
sortmat <- unique(depmat[-1,])[order(unique(depmat)[-1,1], unique(depmat)[-1,3]),] | |
pkglist <- unname(sortmat[!duplicated(sortmat[,1], fromLast = T),]) | |
return(pkglist) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment