Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

There are basically two options for creating a personal library of R programs.
  1. create a library for a version of R in your home directory that makes packages available whenever you run R.
  2. 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 the R environment module
    module load R/3.02
  2. launch R
    R
  3. then install the package, using generic package_name here
    install.packages("package_name", repos="http://cran.r-project.org")
  4. Assuming that you do not have a personal library directory you will see
    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 package should download and install into your personal library directory

Packrat Project Directory

The R stacks on the HPC clusters, 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.

  1. create a directory where you want you want to store the project.
  2. cd to the above directory
  3. start R
  4. at the R prompt, initialize the packrat project with
    packrat::init()
  5. From this point on you are working in a packrat project. Installed packages will go into a library within this project.
  6. To restart a packrat project simply start R from the directory created in step (1). The project will initialize automatically.
  • No labels