Installing R Packages in Non-system Directories

Introduction

You can install and execute your own R packages in non-system directories. This is handy when you're working on machines without system access. To avoid network and computational degradation, the directories for your personal packages should be placed on the local hard drive of the machine. Local directories include: /Users/Shared/<username> (on any machine), /data/<username> (on computation servers).

The directory can be named whatever you want. Let's assume, for this example, that the directory is named "myRlibs" and that it is located under the /Users/Shared/<username> directory. It can be created from the Terminal shell with the following command:

mkdir -p /Users/Shared/<username>/myRlibs

Installing a Package

  1. Set the R_LIBS environment variable, so R can find your packages.
    In tcsh:
    setenv R_LIBS /Users/Shared/<username>/myRlibs
    In bash:
    export R_LIBS=/Users/Shared/<username>/myRlibs
    These settings can be saved in ~/.tcshrc (for tcsh users) or ~/.profile (for bash users).
  2. Start R
  3. At the R command prompt type:
    .libPaths();
    This will show you a list of directories where packages are installed. You should see the system directory and the directory that was defined in step 1.
  4. Install a package ("aaMI" in this example):
    install.packages("aaMI_1.0-1",lib="/Users/Shared/<username>/myRlibs",epos=NULL);
    You should see that the package is installed in /Users/Shared/<username>/myRlibs. With the R_LIBS environment variable set to include this directory, all future R sessions will now find this package.

Comments

/groups/answers/search/index.rss?tag=hotlist/groups/answers/search/?tag=hotWhat’s HotHotListHot!?tag=hot0/groups/answers/sidebar/HotListNo items tagged with hot.hot/groups/answers/search/index.rss?sort=modifiedDate&kind=all&sortDirection=reverse&excludePages=wiki/welcomelist/groups/answers/search/?sort=modifiedDate&kind=all&sortDirection=reverse&excludePages=wiki/welcomeRecent ChangesRecentChangesListUpdates?sort=modifiedDate&kind=all&sortDirection=reverse&excludePages=wiki/welcome0/groups/answers/sidebar/RecentChangesListmodifiedDateallRecent ChangesRecentChangesListUpdateswiki/welcomeNo recent changes.reverse5search