tags:

views:

141

answers:

3

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?

+2  A: 

This is documented in the 'R Installation and Administration' manual that came with your installation.

On my Linux box:

R> .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"      
[3] "/usr/lib/R/library"           
R> 

meaning that the default path is the first of these. You can override that via an argument to both install.packages() (from inside R) or R CMD INSTALL (outside R).

You can also override by setting the R_LIBS_USER variable.

Dirk Eddelbuettel
I've got a Windows Vista machine, but assuming the same procedure exists, do you specify the directory in the install.packages() argument list along with the package name?
Milktrader
Have you discovered 'help(install.packages)' yet? Also, see 'help(Startup)' as per my last comment. And do read those manuals. Lastly, on *doze I tend to just set R_LIBS="C:/opt/R/library" in a file .Renviron. I know you are going to ask about that too -- so do read help(Startup). Ok? ;-)
Dirk Eddelbuettel
I've got a dozen R manuals on my Kindle (including the 3,000+ page one) and wasn't aware of the Startup help file. I've been reading the manuals and hit a dead-end. Go figure it was a simple answer all along. Do I lose points for RTFM questions <- I don't have many to lose. Thanks again Dirk. See you at R/Finance next week. Ramping up on R skills as best I can so I don't get dusted during the presentations.
Milktrader
The 3000+ page is a collation of all the help page -- least helpful. The aforemention 'Installation and Admin' one should be very useful for what you are after here.
Dirk Eddelbuettel
+1  A: 

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.

James Thompson
this is what I'd like to do, but how do I access and .Rprofile? The prompt doesn't recognize it as either an object or a function
Milktrader
It is a _file_. Again, read the fine manual, and/or help(Startup).
Dirk Eddelbuettel
you've got me started ... I know, RTFM. Thanks
Milktrader
+1  A: 

Thanks for the direction from the above two answerers. James Thompson's suggestion worked best for Windows users.

  1. Go to where your R program is installed. This is referred to as R_Home in the literature. Once you find it, go to the /etc subdirectory.

C:\R\R-2.10.1\etc

  1. Select the file in this folder named Rprofile.site. I open it with VIM. You will find this is a bare-bones file with less than 20 lines of code. I inserted the following inside the code:

my custom library path

.libPaths=("C:/R/library")

-the comment added to keep track of what I did to the file.

  1. In R, typing the .libPaths() function yields the first target at C:/R/Library

NOTE: there is likely more than one way to achieve this, but other methods I tried didn't work for some reason.

Milktrader