Uninstall (remove) R package with dependencies

95    Asked by HannahDyer in Data Science , Asked on Sep 3, 2025

How can you uninstall an R package along with its dependencies?  Sometimes unused packages clutter your environment, and removing them properly helps free up space and keep your R setup clean.

Answered by Hybrid Serpente

In R, uninstalling a package is quite simple, but if you also want to remove its dependencies, you need to be a little more careful. Dependencies are other packages that were installed because the main package needed them. Over time, unused packages can take up space or even cause version conflicts, so it’s a good practice to clean them up.

Here are some ways to remove an R package with dependencies:

Basic uninstall using remove.packages()

   remove.packages("dplyr")

 This removes only the specified package (dplyr in this case) but not its dependencies.

Using pacman package

 The pacman package makes managing packages easier. With p_delete() you can remove multiple packages at once:

   pacman::p_delete("dplyr", "ggplot2")

Using BiocManager (for Bioconductor packages)

 If you’re dealing with Bioconductor packages, you can use:

   BiocManager::remove("pkgName")

Removing unused dependencies

 One approach is to use the pacman or tools package to check for orphaned packages (dependencies no longer needed) and then remove them. Unfortunately, R does not have a built-in “remove with dependencies” command like some Linux package managers, so you may need to manually identify and remove those.

 In short, remove.packages() will delete the main package, but for dependencies, you’ll either need helper packages like pacman or manually remove them. Keeping your R environment clean ensures better performance and avoids unnecessary conflicts.



Your Answer

Interviews

Parent Categories