was successfully added to your cart.


A little while ago I ran into an issue with R and RStudio. In order to solve this issue I saw myself forced to remove all user installed packages. For a lot of practical reasons it was not an option for me to simply uninstall R and start with a clean slate and a new installation of R.

Therefore I had to find another solution which could help me with removing all user installed packages. I found a few useful tips and tricks, but nothing that immediately did the job for me. That’s why I’ve decided to share my solution, I hope this can help you in the hour of need.

Here is the script I’ve created in order to remove all user installed packages, without removing any base packages for R or MRO.

# create a list of all installed packages
 ip <- as.data.frame(installed.packages())
# if you use MRO, make sure that no packages in this library will be removed
 ip <- subset(ip, !grepl("MRO", ip$LibPath))
# we don't want to remove base or recommended packages either\
 ip <- ip[!(ip[,"Priority"] %in% c("base", "recommended")),]
# determine the library where the packages are installed
 path.lib <- unique(ip$LibPath)
# create a vector with all the names of the packages you want to remove
 pkgs.to.remove <- ip[,1]
# remove the packages
 sapply(pkgs.to.remove, remove.packages, lib = path.lib)

this article is written by

Jeanine Schoonemann

One Comment

  • Joseph says:

    well. did this and I am now getting the following error on simple loops as such:

    > for (i in 1:3) {print(i)}
    Error in check_reserved(for_var_name) :
    could not find function “check_reserved”

    needed to reinstall everything and still cant get it working. really screwed it down to the core.