Skip to content

Instantly share code, notes, and snippets.

View wzehui's full-sized avatar
🚩
Focusing

Zehui Wang wzehui

🚩
Focusing
View GitHub Profile
@duttashi
duttashi / remove_pkg_dep.R
Created August 21, 2017 23:45
To uninstall a R package and all its dependencies
# 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,