Installing R Packages in Your Own Directories

Article ID: 542
Last updated: 25 Aug, 2026

R is a language and environment for statistical computing and graphics. For the NAS Athena system running the TOSS5 operating system, it is available after loading the cray-R module. For other NAS x86_64 systems running the TOSS4 operating system, is available through the NetBSD Packages Collection (pkgsrc).

After invoking R, you can check the package name, location, and version included in the installation via the installed.packages() command. You can install additional R packages in your own directories for your own use.

Recommendation: Pre-create a directory (such as ~/R-packages) and set the R_LIBS_USER environment variable before installing R packages. (See sample steps below.)

Alternatively, you can use one of these methods to install R packages in your own directory:

  • Pre-create a directory (such as ~/R-packages). During installation, add the lib="/u/your_username/R-packages" option to the install.packages function.
  • During the installation step that includes the install.packages function, answer yes (y) to both of these questions: (1) Would you like to use a personal library instead? and (2) Would you like to create a personal library ~/R/x86_64-redhat-linux-gnu-library/r-version-number?

Sample Steps

In the following sample steps, the recommended method described above is used to install the xts package (along with the zoo package, on which it has a dependency) on Athena. The example shows a few possible arguments you can choose for the install.packages function.

Step 1: Pre-Create a Directory

Pre-create a directory and set the R_LIBS_USER environment variable:

% mkdir ~/R-packages
% setenv R_LIBS_USER ~/R-packages (for csh) 
or 
% export R_LIBS_USER=~/R-packages (for bash)

Step 2: Load and Start R

Load a module that includes R and start R:

% module load cray-R/4.4.0
% R

Note: If you want to run R on other NAS x86_64 systems, version 4.2.0 is available through pkgsrc/2023Q3, and version 4.5.2 is available through pkgsrc/2026Q1:

% module load pkgsrc/2023Q3
% R

or

% module use /nasa/modulefiles/testing
% module load pkgsrc/2026Q1
% R

You may also need to load a newer gcc compiler if you encounter compilation errors during installation:

% module load gcc/13.2

Step 3: Identify a Download Site for Packages

At the R prompt >, choose one of the following methods to identify a download site for the packages from the Comprehensive R Archive Network (CRAN) and install the packages.

Method 1

> install.packages("xts")

If you use this method, a list of secure CRAN mirror sites will appear on your screen or in a separate pop-up window. Choose one of the USA sites, for example, USA (TN), as a source for downloading the zoo and xts packages.

Method 2

> install.packages("xts",repos="http://cran.r-project.org")

You can specify a different site, such as:

  • https://mirror.chpc.utah.edu/pub/cran/
  • https://mirrors.nics.utk.edu/cran

For all possible mirror sites, see https://cran.r-project.org/CRAN_mirrors.csv.

Method 3

> install.packages("http://cran.r-project.org/src/contrib/zoo_1.9-0.tar.gz", type="source")
> install.packages("http://cran.r-project.org/src/contrib/xts_0.14.2.tar.gz", type="source")

Additional Resources

For more information about R, including technical documentation, see the R Project website.

Contact Us

General User Assistance

Security

  • Report security issues 24x7x365
  • Toll-free: 1-877-NASA-SEC (1-877-627-2732)
  • E-mail: soc@nasa.gov

User Documentation

High-End Computing Capability (HECC) Portfolio Office

NASA High-End Computing Program

Tell Us About It

Our goal is furnish all the information you need to efficiently and effectively use the HECC resources needed for your NASA computational projects.

We welcome your input on features and topics that you would like to see included on this website.

Please send us email with your wish list and other feedback.