Categories
Misc

Removing packages installed in Rstudio

I recently switched from Macports to Homebrew. That meant using a new, ‘homebrewed’ version of R, rather than a ‘macported’ one. 

I had problems, and couldn’t find anything too helpful online, so hopefully this will serve as a guide to the next person who runs across this it.

RStudio kept giving me errors about outdated packages, but I couldn’t uninstall them. I followed these instructions, but Rstudio kept saying that the relevant packages couldn’t be found.

Here’s why : Rstudio installs packages in a completely separate place than where “normal R” packages are saved. Crazy, right?

So, if you’re trying to uninstall Rstudio packages on a Mac, try this:

.libPaths()

Will show you the different places your library is. Note the last parameter. It might look something like this: ’/Applications/RStudio.app/Contents/Resources/R/library’

ip <- installed.packages()

pkgs.to.remove <- ip[!(ip[,“Priority”] %in% c(“base”, “recommended”)), 1]

sapply(pkgs.to.remove, remove.packages, ’/Applications/RStudio.app/Contents/Resources/R/library’)

Or replace ’/Applications/RStudio.app/Contents/Resources/R/library’ with whatever isn’t the first result from .libPaths().

You might have to repeat steps 2-4 a few times. Enjoy!