Changes between Initial Version and Version 1 of cypress/InstallingRPackages


Ignore:
Timestamp:
Feb 10, 2020 1:38:36 PM (22 months ago)
Author:
cbaribault
Comment:

Created separate wiki page for installing R packages on Cypress.

Legend:

Unmodified
Added
Removed
Modified
  • cypress/InstallingRPackages

    v1 v1  
     1[[PageOutline]]
     2
     3== [=#InstallingRPackages Installing R Packages on Cypress] ==
     4If you want to use some R packages that are not yet installed in your desired version of R on Cypress,
     5then you have several alternatives, as prescribed below, for locations for installing those packages. Those locations include either your user home directory or lustre sub-directory, and the methods will vary depending on your desired level of reproducibility.
     6
     7=== [=#RPackageAlternative1 Alternative 1] - default to home sub-directory ===
     8From your R session, you may choose to have R install its packages into a sub-directory under your home directory.
     9By 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.
     10
     11{{{
     12> R.version.string
     13[1] "R version 3.4.1 (2017-06-30)"
     14> install.packages("copula")
     15Installing package into ‘/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib’
     16(as ‘lib’ is unspecified)
     17Warning in install.packages("copula") :
     18  'lib = "/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib"' is not writable
     19Would you like to use a personal library instead?  (y/n) y
     20Would you like to create a personal library
     21~/R/x86_64-pc-linux-gnu-library/3.4
     22to install packages into?  (y/n) y
     23--- Please select a CRAN mirror for use in this session ---
     24PuTTY X11 proxy: unable to connect to forwarded X server: Network error: Connection refused
     25HTTPS CRAN mirror
     26
     27 1: 0-Cloud [https]                   2: Algeria [https]
     28...
     2979: Vietnam [https]                  80: (HTTP mirrors)
     30
     31
     32Selection: 77
     33...
     34}}}
     35
     36Note that the above example was performed without X11 forwarding, resulting in a prompt at the command line for selection of a CRAN mirror site in the above, at which point you should enter the number corresponding to the desired mirror site, e.g. '''77'''.
     37
     38=== Alternative 2 - specify your lustre sub-directory via exported environment variable ===
     39Alternatively, 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.
     40The environmental variable **R_LIBS_USER** points the desired location of user package(s).
     41
     42First, create a directory and export the environment variable.
     43{{{
     44mkdir -p /lustre/project/<your-group-name>/R/Library
     45export R_LIBS_USER=/lustre/project/<your-group-name>/R/Library
     46}}}
     47
     48Then run R and install a package. Note that we can use the R function **.libPaths()** as confirmation of the user library location.
     49{{{
     50> .libPaths()
     51[1] "/lustre/project/<your-group-name>/R/Library"
     52[2] "/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib"
     53[3] "/share/apps/R/3.4.1-intel/lib64/R/library"
     54> install.packages("copula")
     55Installing package into ‘/lustre/project/<your-group-name>/R/Library’
     56(as ‘lib’ is unspecified)
     57...
     58}}}
     59
     60=== Alternative 3 - specify lustre sub-directory via environment file ===
     61Similarly, you may accomplish the above via the same environment variable setting as above but in a local file as in the following.
     62
     63First, create a directory as above.
     64{{{
     65mkdir -p /lustre/project/<your-group-name>/R/Library
     66}}}
     67Then setting **R_LIBS_USER** in the file **~/.Renviron** will tell R a default location.
     68
     69Note 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!
     70
     71{{{
     72echo 'R_LIBS_USER="/lustre/project/<your-group-name>/R/Library"' > ~/.Renviron
     73}}}
     74Or use a text editor in order to create and edit the file **~/.Renviron** so that the file includes the following line.
     75{{{
     76R_LIBS_USER="/lustre/project/<your-group-name>/R/Library"
     77}}}
     78
     79Then run R and install a package. Note again the use of R function **.libPaths()** as confirmation of the user library location.
     80{{{
     81> .libPaths()
     82[1] "/lustre/project/<your-group-name>/R/Library"
     83[2] "/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib"
     84[3] "/share/apps/R/3.4.1-intel/lib64/R/library"
     85> install.packages("copula")
     86Installing package into ‘/lustre/project/<your-group-name>/R/Library’
     87(as ‘lib’ is unspecified)
     88...
     89}}}
     90
     91=== Alternative 4 - specify lustre sub-directory via R profile file ===
     92Similarly, you may set the sub-directory depending on R major.minor version via the R profile file as in the following.
     93
     94Edit the file **~/.Rprofile** as follows.
     95{{{
     96majorMinorPatch <- paste(R.version[c("major", "minor")], collapse=".")
     97majorMinor <- gsub("(.*)\\..*", "\\1", majorMinorPatch)
     98#print(paste0("majorMinor=", majorMinor))
     99myLibPath <- paste0("/lustre/project/<your-group-name>/R/Library/", majorMinor)
     100dir.create(myLibPath, showWarnings = FALSE)
     101#print(paste0("myLibPath=", myLibPath))
     102newLibPaths <- c(myLibPath, .libPaths())
     103.libPaths(newLibPaths)
     104}}}
     105
     106Note that setting the R library trees directly via the R function **.libPaths()** in the file **~/.Rprofile** can thus either //override// or //append// to that of any previously set value of **R_LIBS_USER**!
     107
     108Then run R and install a package. Note again the use of R function **.libPaths()** as confirmation of the user library location.
     109{{{
     110> .libPaths()
     111[1] "/lustre/project/<your-group-name>/R/Library/3.4"
     112[2] "/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib"
     113[3] "/share/apps/R/3.4.1-intel/lib64/R/library"
     114> install.packages("copula")
     115Installing package into ‘/lustre/project/<your-group-name>/R/Library/3.4’
     116(as ‘lib’ is unspecified)
     117...
     118}}}
     119
     120=== Alternative 5 - specify lustre sub-directory via R code ===
     121As for yet another alternative, you can accomplish the above entirely in your R code via the following.
     122First, create a directory as before.
     123{{{
     124mkdir -p /lustre/project/<your-group-name>/R/Library
     125}}}
     126
     127Then 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()**.
     128{{{
     129> myLib := "/lustre/project/<your-group-name>/R/Library"
     130> install.packages("copula",lib=myLib)
     131...
     132> library(copula, lib.loc=myLib)
     133}}}
     134