Changes between Version 10 and Version 11 of cypress/R


Ignore:
Timestamp:
08/21/17 16:50:36 (7 years ago)
Author:
cbaribault
Comment:

CEB 20170821 - Added multiple alternatives for installing R packages.

Legend:

Unmodified
Added
Removed
Modified
  • cypress/R

    v10 v11  
    201201
    202202
    203 == Installing Packages into user home directory ==
    204 If you want to use some packages but those aren't installed into the R on Cypress,
    205 you can install those into your home directory.
    206 
    207 First, create a directory and set an environmental variable,
    208 {{{
    209 mkdir -p ~/R/Library
    210 export R_LIB_USER=/home/USERID/R/Library
     203== Installing R Packages into user home directory or lustre sub-directory ==
     204If you want to use some R packages that are not yet installed in your desired version of R on Cypress,
     205then you have several alternatives - depending on your desired level of reproducibility.
     206
     207=== Alternative 1 - default to home sub-directory ===
     208From your R session, you may choose to have R install its packages into a sub-directory under your home directory.
     209By default R will create such a sub-directory whose name corresponds to the R version of your current R session and install your packages there.
     210
     211{{{
     212> R.version.string
     213[1] "R version 3.4.1 (2017-06-30)"
     214> install.packages("copula")
     215Installing package into ‘/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib’
     216(as ‘lib’ is unspecified)
     217Warning in install.packages("copula") :
     218  'lib = "/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib"' is not writable
     219Would you like to use a personal library instead?  (y/n) y
     220Would you like to create a personal library
     221~/R/x86_64-pc-linux-gnu-library/3.4
     222to install packages into?  (y/n) y
     223...
     224}}}
     225
     226=== Alternative 2 - specify your lustre sub-directory via exported environment variable ===
     227Alternatively, if you prefer to use, say, your lustre sub-directory rather than your home directory, then you may do so via an exported environment variable setting as in the following.
     228The environmental variable **R_LIBS_USER** points the desired location of user package(s).
     229
     230First, create a directory and export the environment variable.
     231{{{
     232mkdir -p /lustre/project/<your-group-name>/R/Library
     233export R_LIB_USER=/lustre/project/<your-group-name>/R/Library
    211234}}}
    212 The environmental variable R_LIBS_USER points the location of user package.
    213 Setting in ~/.Renviron to tell R a default location,
    214 {{{
    215 echo 'R_LIBS_USER="~/R/Library"' > $HOME/.Renviron
     235
     236Then run R and install a package. Note that we can use the R function **.libPaths()** as confirmation of the user library location.
     237{{{
     238> .libPaths()
     239[1] "/lustre/project/<your-group-name>/R/Library"
     240[2] "/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib"
     241[3] "/share/apps/R/3.4.1-intel/lib64/R/library"
     242> install.packages("copula")
     243Installing package into ‘/lustre/project/<your-group-name>/R/Library’
     244(as ‘lib’ is unspecified)
     245...
     246}}}
     247
     248=== Alternative 3 - specify lustre sub-directory via environment file ===
     249Similarly, you may accomplish the above via the same environment variable setting as above but in a local file as in the following.
     250
     251First, create a directory as above.
     252{{{
     253mkdir -p /lustre/project/<your-group-name>/R/Library
     254}}}
     255Then setting **R_LIBS_USER** in the file **~/.Renviron** will tell R a default location.
     256
     257Note however that setting or unsetting the environment variable **R_LIBS_USER** in the file **~/.Renviron** will //override// any previously exported value of that same environment variable!
     258
     259{{{
     260echo 'R_LIBS_USER="/lustre/project/<your-group-name>/R/Library"' > ~/.Renviron
     261}}}
     262Or use a text editor in order to create and edit the file **~/.Renviron** so that the file includes the following line.
     263{{{
     264R_LIBS_USER="/lustre/project/<your-group-name>/R/Library"
     265}}}
     266
     267Then run R and install a package. Note again the use of R function **.libPaths()** as confirmation of the user library location.
     268{{{
     269> .libPaths()
     270[1] "/lustre/project/<your-group-name>/R/Library"
     271[2] "/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib"
     272[3] "/share/apps/R/3.4.1-intel/lib64/R/library"
     273> install.packages("copula")
     274Installing package into ‘/lustre/project/<your-group-name>/R/Library’
     275(as ‘lib’ is unspecified)
     276...
     277}}}
     278
     279=== Alternative 4 - specify lustre sub-directory via R profile file ===
     280Similarly, you may set the sub-directory depending on R major.minor version via the R profile file as in the following.
     281
     282Edit the file **~/.Rprofile** as follows.
     283{{{
     284majorMinorPatch <- paste(R.version[c("major", "minor")], collapse=".")
     285majorMinor <- gsub("(.*)\\..*", "\\1", majorMinorPatch)
     286#print(paste0("majorMinor=", majorMinor))
     287myLibPath <- paste0("/lustre/project/<your-group-name>/R/Library/", majorMinor)
     288dir.create(myLibPath, showWarnings = FALSE)
     289#print(paste0("myLibPath=", myLibPath))
     290newLibPaths <- c(myLibPath, .libPaths())
     291.libPaths(newLibPaths)
     292}}}
     293
     294Note however that setting the R library trees directly via **.libPaths()** in the file **~/.Rprofile** will //override// any previously set value of **R_LIBS_USER**!
     295
     296Then run R and install a package. Note again the use of R function **.libPaths()** as confirmation of the user library location.
     297{{{
     298> .libPaths()
     299[1] "/lustre/project/<your-group-name>/R/Library/3.4"
     300[2] "/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib"
     301[3] "/share/apps/R/3.4.1-intel/lib64/R/library"
     302> install.packages("copula")
     303Installing package into ‘/lustre/project/<your-group-name>/R/Library/3.4’
     304(as ‘lib’ is unspecified)
     305...
     306}}}
     307
     308=== Alternative 5 - specify lustre sub-directory via R code ===
     309As for yet another alternative, you can accomplish the above entirely in your R code via the following.
     310First, create a directory as before.
     311{{{
     312mkdir -p /lustre/project/<your-group-name>/R/Library
    216313}}}
    217 Or use a text editor.
    218 
    219 Run R and install a package
    220 {{{
    221 > install.packages("copula",lib="~/R/Library")
     314
     315Then run R and install a package, but note that you must also specify the location from which to load the package in the ensuing call to the R function **library()**.
     316{{{
     317> myLib := "/lustre/project/<your-group-name>/R/Library"
     318> install.packages("copula",lib=myLib)
     319...
     320> library(copula, lib.loc=myLib)
    222321}}}
    223322