| 328 |  | If you want to use some R packages that are not yet installed in your desired version of R on Cypress, | 
          
            | 329 |  | 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. | 
          
            | 330 |  |  | 
          
            | 331 |  | === [=#RPackageAlternative1 Alternative 1] - default to home sub-directory === | 
          
            | 332 |  | From your R session, you may choose to have R install its packages into a sub-directory under your home directory. | 
          
            | 333 |  | 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. | 
          
            | 334 |  |  | 
          
            | 335 |  | {{{ | 
          
            | 336 |  | > R.version.string | 
          
            | 337 |  | [1] "R version 3.4.1 (2017-06-30)" | 
          
            | 338 |  | > install.packages("copula") | 
          
            | 339 |  | Installing package into ‘/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib’ | 
          
            | 340 |  | (as ‘lib’ is unspecified) | 
          
            | 341 |  | Warning in install.packages("copula") : | 
          
            | 342 |  | 'lib = "/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib"' is not writable | 
          
            | 343 |  | Would you like to use a personal library instead?  (y/n) y | 
          
            | 344 |  | Would you like to create a personal library | 
          
            | 345 |  | ~/R/x86_64-pc-linux-gnu-library/3.4 | 
          
            | 346 |  | to install packages into?  (y/n) y | 
          
            | 347 |  | --- Please select a CRAN mirror for use in this session --- | 
          
            | 348 |  | PuTTY X11 proxy: unable to connect to forwarded X server: Network error: Connection refused | 
          
            | 349 |  | HTTPS CRAN mirror | 
          
            | 350 |  |  | 
          
            | 351 |  | 1: 0-Cloud [https]                   2: Algeria [https] | 
          
            | 352 |  | ... | 
          
            | 353 |  | 79: Vietnam [https]                  80: (HTTP mirrors) | 
          
            | 354 |  |  | 
          
            | 355 |  |  | 
          
            | 356 |  | Selection: 77 | 
          
            | 357 |  | ... | 
          
            | 358 |  | }}} | 
          
            | 359 |  |  | 
          
            | 360 |  | 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'''. | 
          
            | 361 |  |  | 
          
            | 362 |  | === Alternative 2 - specify your lustre sub-directory via exported environment variable === | 
          
            | 363 |  | 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. | 
          
            | 364 |  | The environmental variable **R_LIBS_USER** points the desired location of user package(s). | 
          
            | 365 |  |  | 
          
            | 366 |  | First, create a directory and export the environment variable. | 
          
            | 367 |  | {{{ | 
          
            | 368 |  | mkdir -p /lustre/project/<your-group-name>/R/Library | 
          
            | 369 |  | export R_LIBS_USER=/lustre/project/<your-group-name>/R/Library | 
          
            | 370 |  | }}} | 
          
            | 371 |  |  | 
          
            | 372 |  | Then run R and install a package. Note that we can use the R function **.libPaths()** as confirmation of the user library location. | 
          
            | 373 |  | {{{ | 
          
            | 374 |  | > .libPaths() | 
          
            | 375 |  | [1] "/lustre/project/<your-group-name>/R/Library" | 
          
            | 376 |  | [2] "/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib" | 
          
            | 377 |  | [3] "/share/apps/R/3.4.1-intel/lib64/R/library" | 
          
            | 378 |  | > install.packages("copula") | 
          
            | 379 |  | Installing package into ‘/lustre/project/<your-group-name>/R/Library’ | 
          
            | 380 |  | (as ‘lib’ is unspecified) | 
          
            | 381 |  | ... | 
          
            | 382 |  | }}} | 
          
            | 383 |  |  | 
          
            | 384 |  | === Alternative 3 - specify lustre sub-directory via environment file === | 
          
            | 385 |  | Similarly, you may accomplish the above via the same environment variable setting as above but in a local file as in the following. | 
          
            | 386 |  |  | 
          
            | 387 |  | First, create a directory as above. | 
          
            | 388 |  | {{{ | 
          
            | 389 |  | mkdir -p /lustre/project/<your-group-name>/R/Library | 
          
            | 390 |  | }}} | 
          
            | 391 |  | Then setting **R_LIBS_USER** in the file **~/.Renviron** will tell R a default location. | 
          
            | 392 |  |  | 
          
            | 393 |  | 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! | 
          
            | 394 |  |  | 
          
            | 395 |  | {{{ | 
          
            | 396 |  | echo 'R_LIBS_USER="/lustre/project/<your-group-name>/R/Library"' > ~/.Renviron | 
          
            | 397 |  | }}} | 
          
            | 398 |  | Or use a text editor in order to create and edit the file **~/.Renviron** so that the file includes the following line. | 
          
            | 399 |  | {{{ | 
          
            | 400 |  | R_LIBS_USER="/lustre/project/<your-group-name>/R/Library" | 
          
            | 401 |  | }}} | 
          
            | 402 |  |  | 
          
            | 403 |  | Then run R and install a package. Note again the use of R function **.libPaths()** as confirmation of the user library location. | 
          
            | 404 |  | {{{ | 
          
            | 405 |  | > .libPaths() | 
          
            | 406 |  | [1] "/lustre/project/<your-group-name>/R/Library" | 
          
            | 407 |  | [2] "/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib" | 
          
            | 408 |  | [3] "/share/apps/R/3.4.1-intel/lib64/R/library" | 
          
            | 409 |  | > install.packages("copula") | 
          
            | 410 |  | Installing package into ‘/lustre/project/<your-group-name>/R/Library’ | 
          
            | 411 |  | (as ‘lib’ is unspecified) | 
          
            | 412 |  | ... | 
          
            | 413 |  | }}} | 
          
            | 414 |  |  | 
          
            | 415 |  | === Alternative 4 - specify lustre sub-directory via R profile file === | 
          
            | 416 |  | Similarly, you may set the sub-directory depending on R major.minor version via the R profile file as in the following. | 
          
            | 417 |  |  | 
          
            | 418 |  | Edit the file **~/.Rprofile** as follows. | 
          
            | 419 |  | {{{ | 
          
            | 420 |  | majorMinorPatch <- paste(R.version[c("major", "minor")], collapse=".") | 
          
            | 421 |  | majorMinor <- gsub("(.*)\\..*", "\\1", majorMinorPatch) | 
          
            | 422 |  | #print(paste0("majorMinor=", majorMinor)) | 
          
            | 423 |  | myLibPath <- paste0("/lustre/project/<your-group-name>/R/Library/", majorMinor) | 
          
            | 424 |  | dir.create(myLibPath, showWarnings = FALSE) | 
          
            | 425 |  | #print(paste0("myLibPath=", myLibPath)) | 
          
            | 426 |  | newLibPaths <- c(myLibPath, .libPaths()) | 
          
            | 427 |  | .libPaths(newLibPaths) | 
          
            | 428 |  | }}} | 
          
            | 429 |  |  | 
          
            | 430 |  | 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**! | 
          
            | 431 |  |  | 
          
            | 432 |  | Then run R and install a package. Note again the use of R function **.libPaths()** as confirmation of the user library location. | 
          
            | 433 |  | {{{ | 
          
            | 434 |  | > .libPaths() | 
          
            | 435 |  | [1] "/lustre/project/<your-group-name>/R/Library/3.4" | 
          
            | 436 |  | [2] "/share/apps/spark/spark-2.0.0-bin-hadoop2.6/R/lib" | 
          
            | 437 |  | [3] "/share/apps/R/3.4.1-intel/lib64/R/library" | 
          
            | 438 |  | > install.packages("copula") | 
          
            | 439 |  | Installing package into ‘/lustre/project/<your-group-name>/R/Library/3.4’ | 
          
            | 440 |  | (as ‘lib’ is unspecified) | 
          
            | 441 |  | ... | 
          
            | 442 |  | }}} | 
          
            | 443 |  |  | 
          
            | 444 |  | === Alternative 5 - specify lustre sub-directory via R code === | 
          
            | 445 |  | As for yet another alternative, you can accomplish the above entirely in your R code via the following. | 
          
            | 446 |  | First, create a directory as before. | 
          
            | 447 |  | {{{ | 
          
            | 448 |  | mkdir -p /lustre/project/<your-group-name>/R/Library | 
          
            | 449 |  | }}} | 
          
            | 450 |  |  | 
          
            | 451 |  | 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()**. | 
          
            | 452 |  | {{{ | 
          
            | 453 |  | > myLib := "/lustre/project/<your-group-name>/R/Library" | 
          
            | 454 |  | > install.packages("copula",lib=myLib) | 
          
            | 455 |  | ... | 
          
            | 456 |  | > library(copula, lib.loc=myLib) | 
          
            | 457 |  | }}} | 
          
            |  | 328 | See [wiki:InstallingRPackages  here.] | 
          
            |  | 329 |  |