| 1 | [[PageOutline]] |
| 2 | |
| 3 | == [=#InstallingRPackages Installing R Packages on Cypress] == |
| 4 | If you want to use some R packages that are not yet installed in your desired version of R on Cypress, |
| 5 | then 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 === |
| 8 | From your R session, you may choose to have R install its packages into a sub-directory under your home directory. |
| 9 | By 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") |
| 15 | Installing package into ‘/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib’ |
| 16 | (as ‘lib’ is unspecified) |
| 17 | Warning in install.packages("copula") : |
| 18 | 'lib = "/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib"' is not writable |
| 19 | Would you like to use a personal library instead? (y/n) y |
| 20 | Would you like to create a personal library |
| 21 | ~/R/x86_64-pc-linux-gnu-library/3.4 |
| 22 | to install packages into? (y/n) y |
| 23 | --- Please select a CRAN mirror for use in this session --- |
| 24 | PuTTY X11 proxy: unable to connect to forwarded X server: Network error: Connection refused |
| 25 | HTTPS CRAN mirror |
| 26 | |
| 27 | 1: 0-Cloud [https] 2: Algeria [https] |
| 28 | ... |
| 29 | 79: Vietnam [https] 80: (HTTP mirrors) |
| 30 | |
| 31 | |
| 32 | Selection: 77 |
| 33 | ... |
| 34 | }}} |
| 35 | |
| 36 | Note 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 === |
| 39 | Alternatively, 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. |
| 40 | The environmental variable **R_LIBS_USER** points the desired location of user package(s). |
| 41 | |
| 42 | First, create a directory and export the environment variable. |
| 43 | {{{ |
| 44 | mkdir -p /lustre/project/<your-group-name>/R/Library |
| 45 | export R_LIBS_USER=/lustre/project/<your-group-name>/R/Library |
| 46 | }}} |
| 47 | |
| 48 | Then 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") |
| 55 | Installing 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 === |
| 61 | Similarly, you may accomplish the above via the same environment variable setting as above but in a local file as in the following. |
| 62 | |
| 63 | First, create a directory as above. |
| 64 | {{{ |
| 65 | mkdir -p /lustre/project/<your-group-name>/R/Library |
| 66 | }}} |
| 67 | Then setting **R_LIBS_USER** in the file **~/.Renviron** will tell R a default location. |
| 68 | |
| 69 | Note 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 | {{{ |
| 72 | echo 'R_LIBS_USER="/lustre/project/<your-group-name>/R/Library"' > ~/.Renviron |
| 73 | }}} |
| 74 | Or use a text editor in order to create and edit the file **~/.Renviron** so that the file includes the following line. |
| 75 | {{{ |
| 76 | R_LIBS_USER="/lustre/project/<your-group-name>/R/Library" |
| 77 | }}} |
| 78 | |
| 79 | Then 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") |
| 86 | Installing 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 === |
| 92 | Similarly, you may set the sub-directory depending on R major.minor version via the R profile file as in the following. |
| 93 | |
| 94 | Edit the file **~/.Rprofile** as follows. |
| 95 | {{{ |
| 96 | majorMinorPatch <- paste(R.version[c("major", "minor")], collapse=".") |
| 97 | majorMinor <- gsub("(.*)\\..*", "\\1", majorMinorPatch) |
| 98 | #print(paste0("majorMinor=", majorMinor)) |
| 99 | myLibPath <- paste0("/lustre/project/<your-group-name>/R/Library/", majorMinor) |
| 100 | dir.create(myLibPath, showWarnings = FALSE) |
| 101 | #print(paste0("myLibPath=", myLibPath)) |
| 102 | newLibPaths <- c(myLibPath, .libPaths()) |
| 103 | .libPaths(newLibPaths) |
| 104 | }}} |
| 105 | |
| 106 | Note 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 | |
| 108 | Then 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") |
| 115 | Installing 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 === |
| 121 | As for yet another alternative, you can accomplish the above entirely in your R code via the following. |
| 122 | First, create a directory as before. |
| 123 | {{{ |
| 124 | mkdir -p /lustre/project/<your-group-name>/R/Library |
| 125 | }}} |
| 126 | |
| 127 | Then 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 | |