Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
There are basically two options for creating a personal library of R programs.
  1. create Create a library for a version of R in your home directory that makes packages available whenever you run that version of R.
  2. create Create isolated environments for each of your R projects with packrat.

Personal Global R Directory

Installing R packages locally is fairly straightforward.

  1. first load Load the R environment module:
    module load R/3.02
  2. launch Launch R:
    R
  3. then install Install the package, using generic package_name here
    install.packages("package_name", repos="http://cran.r-project.org")
  4. Assuming that If you do not already have a personal library directory for the version of R you are using, you will see a prompt like this:
    Warning in install.packages("package_name", repos = "http://cran.r-project.org") :
    'lib = "/opt/R/3.0.2/lib64/R/library"' is not writable
    Would you like to use a personal library instead?  (y/n)
  5. Select 'y'.
  6. Select 'y' again when prompted to create the directory.
  7. your Your package should download and install into your the newly created personal library directory.

Packrat Project Directory

The R stacks on the HPC clusters, beginning with R-Packrat is an R package which allows you to create an isolated and portable environment for each of your R projects. Packrat is available within R environment modules on the Argon HPC cluster beginning with R/3.3.1, have packrat installed. Packrat allows one to create an isolated and portable environment for R projects. To get started with packrat.

create

. For newer versions of R provided as "stack" environment modules, also load the "r-packrat" environment module corresponding to the "r" module you use.

You can create a new project and use packrat from the R prompt like so:

  1. Create a directory where you want you want to store the project.
  2. cd to the above directory.
  3. start Start R.
  4. at At the R prompt, initialize the packrat project with
    packrat::init()

From this point on, you are working in a packrat project

. Installed packages

, and any packages you install will go into a library within this project.

To restart

a

an existing packrat project, simply

start R from

cd to the desired directory

created in step (1). The project will initialize automatically.

(step 2) and start R there (step 3) and the project will load automatically.

Alternately, you you might find it useful to use packrat from your shell. For example:

  1. mkdir ~/someproject
  2. cd ~/someproject
  3. Rscript -e 'packrat::init(enter=FALSE)'

  4. Rscript -e 'install.packages(c("brms","rstanarm"))'