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
# The below code is adoped from the answer by user `Thomas` posted on StackOverflow https://stackoverflow.com/questions/26573368/uninstall-remove-r-package-with-dependencies | |
library("tools") | |
removeDepends <- function(pkg, recursive = FALSE){ | |
d <- package_dependencies(,installed.packages(), recursive = recursive) | |
depends <- if(!is.null(d[[pkg]])) d[[pkg]] else character() | |
needed <- unique(unlist(d[!names(d) %in% c(pkg,depends)])) | |
toRemove <- depends[!depends %in% needed] | |
if(length(toRemove)){ | |
toRemove <- select.list(c(pkg,sort(toRemove)), multiple = TRUE, |