How to Run R

Input

You can use any text editor to make the appropriate input files for R. Rstudio, an IDE for R, can be used to prepare R scripts.

R Libraries

R includes a base package and additional add-on libraries. Several additional libraries have been installed. To see a list of the installed libraries, at the R command prompt, enter:

library()

Additional libraries can be installed in a personal R library directory. To install a library and its dependencies in this location you will need to run R interactively and issue at the R command line:

install.packages('package_name', dependencies=TRUE)

R will inform you that you can’t write to the global directory, and ask if you want to use a personal library instead. Say yes. R will then prompt you with a path and ask if you want to use this. Say yes. R will then install the library in this location.

See the R Installation and Administration guide for more information on how to customize the install.packages command (for example you could add the repository by including in the argument of your install.packages command the string: repos=”http://cran.r-project.org”).

To see a list of directories that R searches for libraries issue at the R prompt:

.libPaths()

If your group has purchased additional storage and you would like to perform an installation of certain R libraries that would be available to all of your group, you should follow these steps:

  1. request the creation of a shared directory in your group space by opening a ticket at: https://support.idre.ucla.edu/helpdesk or sending an email to hpc@ucla.edu
  2. create an R/<RVERSION> directory in your project directory, for example if your project group is called “bruinsponsor”, the shared directory is called “apps” and the version of R for which you intend to install supplemental libraries is “3.6.0” you would issue:

    mkdir -p /u/project/bruinsponsor/apps/R/3.6.0

  3. in the shared project directory create an Rprofile file. For example:

    /u/project/bruinsponsor/apps/R/Rprofile

    containing the line:

    .libPaths(c(paste("/u/project/bruinsponsor/apps/R/",R.version$major,".",R.version$minor, sep=""), .libPaths()))

  4. each user in your group should issue:

    cat /u/project/bruinsponsor/apps/R/Rprofile >> $HOME/.Rprofile

  5. verify that the new R library location, /u/project/bruinsponsor/apps/R/3.6.0, is loaded into R by starting R and issuing at the R command prompt: .libPaths() you should see something along the lines of: 

    > .libPaths()
    [1] "/u/project/bruinsponsor/apps/R/3.6.0"
    [2] "/u/home/b/bruinuser/R/x86_64-pc-linux-gnu-library/3.6"
    [3] "/u/local/apps/R/3.6.0/gcc-4.9.3_MKL-2018/lib64/R/library"

  6. if /u/project/bruinsponsor/apps/R/3.6.0 is in the first position installation of new R packages will occur in this location and the location will be automatically searched by R at run time (as long as $HOME/.Rprofile is in place as shown above)
  7. if any member of your group would like to perform installation in their own $HOME directories they will need to manipulate the path to the libraries using the .libPaths() command within the R section
  8. packages from Bioconductor can be installed using:
    if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager",lib = .libPaths()[1])
    BiocManager::install(c("BiocParallel", "callr", "xfun","xml2"), update = TRUE, lib = .libPaths()[1])

     

Additional libraries, that are of relevant usage to the Hoffman2 community, can also be installed in the central repository upon request. See Software Installation.

How to Run R in Batch

How to Run R using the Queue Scripts

The easiest way to run R in batch from the login node is to use the queue scripts. See Running a Batch Job for a discussion of the queue scripts and how they are used.

The following queue scripts are available for building and submitting a serial R job:

  1. /u/local/apps/submit_scripts/R_job_submitter.sh
  2. R.q

To learn how to use R_job_submitted.sh script:

/u/local/apps/submit_scripts/R_job_submitter.sh --help   

The script: /u/local/apps/submit_scripts/R_job_submitter.sh generates and submits an R batch job.

You can select the R version and pass several arguments as shown below:

Usage:
/u/local/apps/submit_scripts/R_job_submitter.sh [-n R script name]
[-m memory per slot (in GB)] [-t time in hours] [-hp to run on owned nodes]
[-s number of slots] [-v R version] [-arg argument 1 to pass to R script]
[-arg argument 2 to pass to R script] .... [-arg argument n to pass to R script]
[-ns (to build a submission script without submitting the job)]
[-nts (to not add time stamp to cmd file name)] [ --help ]

How to Run R in Batch using UGE commands

See Running a Batch Job for guidelines to follow to create the required UGE command file. Alternatively, you could create an UGE command file with R.q. After saving the command file, you can modify it as necessary. See Commonly-Used UGE Commands for a list of the most commonly used UGE commands.

Your submission script will need to contain scheduler related information (see Commonly-Used UGE Commands) as well as instructions on how to run R, including the selection of a specific version of R.

  • For sh-based script use:

    . /u/local/Modules/default/init/modules.sh

  • For csh-based script use:

    source /u/local/Modules/default/init/modules.csh

  • followed by:

    module load R/XX.YY.ZZ
    R CMD BATCH filename

where XX.YY.ZZ is a specific version of R installed on the cluster (to see which versions are available issue at the command prompt: module av R) and filename is the name of the R script to be run.

Note: rJava

The R library rJava, a low-level R to Java interface, depends on the exact java version on the computing node. As it may happen that the default version of java on different computational nodes slightly differs (which may be due to an update in progress), rJava may appears to not work on some nodes. In this cases we suggest to modify the R command as follows:

  • For sh-based script use:

    . /u/local/Modules/default/init/modules.sh
    module load R
    R CMD javareconf -e
    R CMD BATCH filename

  • For csh-based script use:

    source /u/local/Modules/default/init/modules.csh
    module load R
    R CMD javareconf -e
    R CMD BATCH filename

How to Run R Interactively

How to Run R Interactively on the Hoffman2 cluster:

To run R interactively, first start an interactive session using qrsh.

At the compute node shell prompt, enter:

module load R
R

To see which versions of R are installed on the cluster use:

module av R

How to Run R Interactively from the UCLA Grid Portal

See How to Run an Application from the UCLA Grid Portal

References

Report Typos and Errors
UCLA OIT

© 2016 UC REGENTS TERMS OF USE & PRIVACY POLICY