| 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 == |
| | 204 | If you want to use some R packages that are not yet installed in your desired version of R on Cypress, |
| | 205 | then you have several alternatives - depending on your desired level of reproducibility. |
| | 206 | |
| | 207 | === Alternative 1 - default to home sub-directory === |
| | 208 | From your R session, you may choose to have R install its packages into a sub-directory under your home directory. |
| | 209 | 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. |
| | 210 | |
| | 211 | {{{ |
| | 212 | > R.version.string |
| | 213 | [1] "R version 3.4.1 (2017-06-30)" |
| | 214 | > install.packages("copula") |
| | 215 | Installing package into ‘/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib’ |
| | 216 | (as ‘lib’ is unspecified) |
| | 217 | Warning in install.packages("copula") : |
| | 218 | 'lib = "/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib"' is not writable |
| | 219 | Would you like to use a personal library instead? (y/n) y |
| | 220 | Would you like to create a personal library |
| | 221 | ~/R/x86_64-pc-linux-gnu-library/3.4 |
| | 222 | to install packages into? (y/n) y |
| | 223 | ... |
| | 224 | }}} |
| | 225 | |
| | 226 | === Alternative 2 - specify your lustre sub-directory via exported environment variable === |
| | 227 | 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. |
| | 228 | The environmental variable **R_LIBS_USER** points the desired location of user package(s). |
| | 229 | |
| | 230 | First, create a directory and export the environment variable. |
| | 231 | {{{ |
| | 232 | mkdir -p /lustre/project/<your-group-name>/R/Library |
| | 233 | export R_LIB_USER=/lustre/project/<your-group-name>/R/Library |
| 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 | |
| | 236 | Then 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") |
| | 243 | Installing 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 === |
| | 249 | Similarly, you may accomplish the above via the same environment variable setting as above but in a local file as in the following. |
| | 250 | |
| | 251 | First, create a directory as above. |
| | 252 | {{{ |
| | 253 | mkdir -p /lustre/project/<your-group-name>/R/Library |
| | 254 | }}} |
| | 255 | Then setting **R_LIBS_USER** in the file **~/.Renviron** will tell R a default location. |
| | 256 | |
| | 257 | 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! |
| | 258 | |
| | 259 | {{{ |
| | 260 | echo 'R_LIBS_USER="/lustre/project/<your-group-name>/R/Library"' > ~/.Renviron |
| | 261 | }}} |
| | 262 | Or use a text editor in order to create and edit the file **~/.Renviron** so that the file includes the following line. |
| | 263 | {{{ |
| | 264 | R_LIBS_USER="/lustre/project/<your-group-name>/R/Library" |
| | 265 | }}} |
| | 266 | |
| | 267 | Then 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") |
| | 274 | Installing 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 === |
| | 280 | Similarly, you may set the sub-directory depending on R major.minor version via the R profile file as in the following. |
| | 281 | |
| | 282 | Edit the file **~/.Rprofile** as follows. |
| | 283 | {{{ |
| | 284 | majorMinorPatch <- paste(R.version[c("major", "minor")], collapse=".") |
| | 285 | majorMinor <- gsub("(.*)\\..*", "\\1", majorMinorPatch) |
| | 286 | #print(paste0("majorMinor=", majorMinor)) |
| | 287 | myLibPath <- paste0("/lustre/project/<your-group-name>/R/Library/", majorMinor) |
| | 288 | dir.create(myLibPath, showWarnings = FALSE) |
| | 289 | #print(paste0("myLibPath=", myLibPath)) |
| | 290 | newLibPaths <- c(myLibPath, .libPaths()) |
| | 291 | .libPaths(newLibPaths) |
| | 292 | }}} |
| | 293 | |
| | 294 | Note 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 | |
| | 296 | Then 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") |
| | 303 | Installing 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 === |
| | 309 | As for yet another alternative, you can accomplish the above entirely in your R code via the following. |
| | 310 | First, create a directory as before. |
| | 311 | {{{ |
| | 312 | mkdir -p /lustre/project/<your-group-name>/R/Library |