OSU Navigation Bar

The Ohio State University

Department of Statistics

Cockins Hall
rollover image OSU Statistics
            Home

design element

OSU Statistics

Home

News

Research & Consulting Groups

People

For Visitors

For Prospective Students

For Current Students, Staff & Faculty

Contact Us



rollover image

For Current Students & Faculty

rollover image

Courses

rollover image

Links

rollover image

Computer Support

rollover image

Internal Documents

rollover image

webmail

Installing R Libraries Locally in Your Home Directory

Often it is desirable to have libraries available to all users, other times if you just want to quickly test something it's easier to install the library locally.

Add-on packages on CRAN come as gzipped tar files named pkg_version.tar.gz, which may in fact be bundles containing more than one package. By default R wants to install these to the library tree rooted at the first directory given in R_LIBS, if set, and then to the default system library location otherwise.

So we'll have to create a directory in the home directory, set a variable to point R at that directory, and then install the package

At the shell prompt type:
  setenv R_LIBS "/home/your_username/R_libs"
then from within R you can do:
  install.packages('package_name', repos="http://cran.r-project.org") and you're done. You can pick any directory to make your personal R library.

Alternatively, if you have downloaded the package you can do:
  setenv R_LIBS "/home/your_username/R_libs"
  R CMD INSTALL -l /home/your_username/R_libs pkg_version.tar.gz

So you don't have to type it every time, put the setenv command in your .cshrc.more file or even better, put the following line in a file called .Renviron in your home directory:
  R_LIBS="/home/your_username/R_libs"

You can have several R library directories if you wish to separate differnt libraries.

Just add these directories to the setenv line, or .Renviron file, like so:
  setenv R_LIBS "/home/your_username/R_libs:/homeyour_username/R_libs_biostat"

Then, to specify the directory to install to use:
  R CMD INSTALL -l lib_directory pkg_version.tar.gz

where lib_directory gives the path to the library tree to install to.



If you have trouble accessing this page, or need an alternate format contact webmaster@stat.osu.edu.