Where does R store packages?

Milktrader picture Milktrader · Apr 10, 2010 · Viewed 219.8k times · Source

The install.packages() function in R is the automatic unzipping utility that gets and install packages in R.

  1. How do I find out what directory R has chosen to store packages?

  2. How can I change the directory in which R stores and accesses packages?

Answer

James Thompson picture James Thompson · Apr 10, 2010

The install.packages command looks through the .libPaths variable. Here's what mine defaults to on OSX:

> .libPaths()
[1] "/Library/Frameworks/R.framework/Resources/library"

I don't install packages there by default, I prefer to have them installed in my home directory. In my .Rprofile, I have this line:

.libPaths( "/Users/tex/lib/R" )

This adds the directory "/Users/tex/lib/R" to the front of the .libPaths variable.