Difference between revisions of "Install R Packages in Your Home Directory"

From CAC Documentation wiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
  
 
= Initial Setup =
 
= Initial Setup =
You only need to do this once to create the $R_LIBS directory and select the CRAN mirror from where the R packages will be obtained:  
+
You only need to do this once to create the $R_LIB directory and select the CRAN mirror from where the R packages will be obtained:  
  
 
# Load the R environment module:
 
# Load the R environment module:
 
#;<pre>module load R</pre>
 
#;<pre>module load R</pre>
 
# Create the directory in which R packages will be installed
 
# Create the directory in which R packages will be installed
#;<pre>mkdir -p $R_LIBS</pre>
+
#;<pre>mkdir -p $R_LIB</pre>
 
# Run R and select <code>0-Cloud [https]</code> CRAN mirror.
 
# Run R and select <code>0-Cloud [https]</code> CRAN mirror.
 
<pre>> getCRANmirrors()
 
<pre>> getCRANmirrors()

Latest revision as of 09:30, 25 February 2020

If you need to install a new R package that's not present in the system, use these instructions to install it in your own home directory:

Initial Setup

You only need to do this once to create the $R_LIB directory and select the CRAN mirror from where the R packages will be obtained:

  1. Load the R environment module:
    module load R
  2. Create the directory in which R packages will be installed
    mkdir -p $R_LIB
  3. Run R and select 0-Cloud [https] CRAN mirror.
> getCRANmirrors()
                               Name           Country              City
1                   0-Cloud [https]           0-Cloud           0-Cloud
2                           0-Cloud           0-Cloud           0-Cloud
3                   Algeria [https]           Algeria           Algiers
4                           Algeria           Algeria           Algiers
5              Argentina (La Plata)         Argentina          La Plata
6      Australia (Canberra) [https]         Australia          Canberra
7              Australia (Canberra)         Australia          Canberra
8   Australia (Melbourne 1) [https]         Australia         Melbourne
9   Australia (Melbourne 2) [https]         Australia         Melbourne
10        Australia (Perth) [https]         Australia             Perth
...

> chooseCRANmirror(ind=1)

Install R Package

  1. Make sure R environment module is loaded:
    module load R; module list R/
  2. Run R
  3. Inside R, install packages like this:
    install.packages('<package name>')