====== R-Studio ====== ===== R-Studio on Open OnDemand ===== As part of Comet, we have RStudio available ready to use from our [[advanced:interactive|Open OnDemand]] portal interface. This makes use of the versions of **R** installed as modules on the HPC. This requires no special software and no interaction with the HPC command line or the Linux desktop environment, since RStudio runs full screen in your browser. Open a web browser and enter the address: https://ood01.comet.hpc.ncl.ac.uk - you can also find the link in our [[started:connecting_onsite|Connecting]] wiki page. The main Open OnDemand web portal interface will load: {{:advanced:software:ood_portal.png?800|}} Select the **RStudio Server** option from the **Interactive Apps** menu: {{:advanced:software:ood_rstudio_menu.png?600|}} Select the **resources** you require for RStudio, choose the paid or free partition you want to run the job, the length of time you want to run the session (max 8 hours) and which Slurm account code you are using for the job - note that the more resources you request, //potentially// the longer you may have to wait until Slurm can allocate your request: {{:advanced:software:ood_rstudio_form.png?600|}} Submit the request and wait for Slurm to schedule the session. In time the session will start, and you can connect to it and use the full-screen RStudio application from within your browser: {{:advanced:software:ood_rstudio_app.png?800|}} If the R modules which are installed are sufficient for your needs, then this is the simplest method to running RStudio and taking advantage of the resources of the HPC. As part of the maintenance of the HPC, the version of RStudio (and in turn, R) will be periodically updated. **Running RStudio on Comet is not a replacement for R at the command line!** Running RStudio interactively //should not// be considered a replacement for running compute intensive R jobs via Slurm. You should run anything that takes a substantial amount of time, or which launches many distinct jobs using the normal [[started:first_job|Slurm job requests]]. ---- ===== Adding Custom R Libraries ===== A lot of //simple// R libraries can be installed from inside the //provided// version of R on Comet using the standard ''install.packages('packagename')'' command you can run from the interactive R session. However, this can become tricky if those R libraries also rely on missing system packages and libraries - both of which would need to be installed before R can compile your new library for you. Whilst you //can// [[faq:038|add your own library path locations]] to work around some of this, it can rapidly become a complex sequence of addition dependencies, re-running R, adjusting paths, etc. It is also impractical for us to install //every single R library// and //every single dependency needed// for those R libraries. If you find yourself needing to install R libraries that //do not compile cleanly// we strongly recommend considering the use of a dedicated R or RStudio container runtime - through which you will have control to install any and all dependencies needed for your additional R libraries. ---- ===== Building your own R / RStudio Installation ===== Building your own custom version of R or RStudio offers the flexibility to install any version of software you want, without any admin permissions, and without waiting for us or the HPC vendor to package up a piece of software for you. It also helps in the long term of reducing the need for further system-wide installed software. You can also use the opportunity to create a single R / RStudio container image which could be shared with your group, so that everyone is able to use the same software, without installing multiple copies of the same R libraries. ==== An Example ==== This basic Apptainer container defintion file installs an Ubuntu LTS image and drops on **R** and **RStudio**. Included at the end of the definition file is an example of how to install additional R libraries during the container build process using ''Rscript''. We **highly** recommend installing R and RStudio in this way if you have complex R library requirements that are not accommodated by the existing R/RStudio modules on the HPC. Once built, the final container ''.sif'' file can be placed in a shared directory used by your project team so that you can all use the same software without having to install multiple copies in each users home directory. Bootstrap: docker From: ubuntu:noble %post # Prevent interactive prompts export DEBIAN_FRONTEND=noninteractive # Update & install only necessary packages apt-get update # Base stuff everything will need apt-get install -y aptitude wget zip git less vim # Add all of the Ubuntu/Debian packages needed to run R here # If any R libraries need further Ubuntu dependencies, list them below apt-get install -y \ build-essential \ cmake \ gcc-14 \ g++-14 \ r-base \ r-base-core \ r-base-dev # These are things *only* needed by RStudio apt-get install -y \ libnspr4 \ libnss3 \ libatk1.0-0 \ libatk-bridge2.0-0 \ libssl-dev \ libclang-dev \ libcups2 \ libgtk-3-0 \ libasound2t64 \ libxkbcommon-x11-0 # Any packages needed for additional R libraries apt-get install -y \ libuv1-dev # Remove any downloaded package files - so they dont remain in the built image apt-get clean ############################################################################## # Set Compiler flags to optimise for Comet CPU hardware ############################################################################## export BASE_CFLAGS="-O3 -march=znver5 -pipe" export CPPFLAGS="" export CFLAGS="$BASE_CFLAGS" export CXXFLAGS="$CFLAGS" export CC=gcc-14 export CXX=g++-14 export FC=gfortran-14 ############################################################################### # Tell R to use the newer version of GCC when it needs to compile. # R *helpfully* ignores standard CC/CFLAG/etc environment variables and # uses its own mechanism for setting the C/C++ and optimisation flags to # use. Override those by writing /root/.R/Makevars instead. ############################################################################### mkdir -p /root/.R/ echo "CC=gcc-14" > /root/.R/Makevars echo "CXX=g++-14" >> /root/.R/Makevars echo "CFLAGS=-O3 -pipe -march=znver5 -fpic" >> /root/.R/Makevars echo "CXXFLAGS=-O3 -pipe -march=znver5 -fpic" >> /root/.R/Makevars echo "CMAKE_C_COMPILER=gcc-14" >> /root/.R/Makevars echo "CMAKE_CXX_COMPILER=g++-14" >> /root/.R/Makevars echo "F77=gfortran-14" >> /root/.R/Makevars # Download and install RStudio mkdir -p /src wget -q https://download1.rstudio.org/electron/jammy/amd64/rstudio-2026.06.0-242-amd64.deb -O /src/rstudio.deb dpkg -i /src/rstudio.deb ############################################################################### # If you need any more R packages, install them below using Rscript: ############################################################################### # This is an example installing the future.batchtools library Rscript -e 'install.packages("fs", repos="https://cloud.r-project.org")' # Remove downloaded source rm -rf /src %environment %runscript ==== Building Your Container ==== To use this definition file to build a new container, run: $ module load apptainer $ export APPTAINER_TMPDIR=/scratch $ apptainer build rstudio.sif rstudio.def You will get a single file; ''rstudio.sif'', which contains the base Ubuntu operating system, plus ''R'' and ''RStudio'', and any additional R libraries you decided to add at the end of the install. ==== Running Your Container ==== We suggest the following runtime helper script to ease running rstudio from inside the container with the minimum amount of command line options: #!/bin/bash module load apptainer IMAGE_NAME=/nobackup/shared/containers/rstudio.sif container.run() { # Run a command inside the container... # automatically bind the /scratch and /nobackup dirs # pass through any additional parameters given on the command line apptainer exec --nv \ --bind /run/dbus:/run/dbus \ --bind /run/user/$UID:/run/user/$UID \ --bind /scratch:/scratch \ --bind /nobackup:/nobackup \ ${IMAGE_NAME} $@ } **Running R** Save the script above as ''rstudio.sh'' and save to a location that you and your project team can access. Adjust the ''IMAGE_NAME'' variable to point to your actual rstudio container file that you have created, then you can run **R** as follows: $ source /path/to/your/rstudio.sh $ container.run R R version 4.3.3 (2024-02-29) -- "Angel Food Cake" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > $ You can use R interactively like this, or can call it from a Slurm job if needed, using the same ''container.run R'' command. **Running RStudio** If you are in an [[advanced:software:x11|Open OnDemand Linux desktop session]], then you can start RStudio as follows: Open up the terminal application from the bottom menu: {{:advanced:software:rstudio_x11_terminal.png?400|}} In the terminal, ''source'' your ''rstudio.sh'' script and run the ''container.run rstudio'' command: $ source /path/to/your/rstudio.sh $ container.run rstudio $ {{:advanced:software:rstudio_x11_source.png?800|}} **RStudio** will start, running from your container: {{:advanced:software:rstudio_x11_app.png?800|}} You should have access to all of the R libraries you chose to install while writing the container definition file. If you use the ''container.run'' command, then you'll also have access to ''/scratch'', ''$HOME'' and ''/nobackup'' directories from withing the RStudio application itself. ==== Limitations ==== Unlike running from //outside// a container, there are a few subtle limitations in running in this way. The most obvious is that the container is **frozen** after being created and does not (normally) allow further updates. As such, if you want to add more R libraries, or additional software, you would usually need to recreate the container by updating your definition file and re-running the ''apptainer build'' steps. ---- [[:advanced:software|Back to software]]