April 13, 2023

How to Navigate this Slide Show?

  • This ioslides presentation contains scrollable slides.
  • Which slides are scrollable, is indicated by a tag at the bottom of the corresponding slides stating:

[ Scroll down to continue ]

  • The following single character keyboard shortcuts enable alternate display modes of ioslides:
    • f: enable fullscreen mode
    • w: toggle widescreen mode
    • o: enable overview mode
    • h: enable code highlight mode
  • Pressing Esc exits all of these modes. Additional details can be found here.


  • Background
  • Neovim-based IDE for R
  • Conclusions
  • References

R Language


  • Statistical environment and programming language (CRAN) widely used in academia and data science.
  • Free and runs on all common operating systems
  • Large ecosystem of extension packages, e.g. Bioconductor and CRAN

Working environments

RStudio Server for Web-based HPCC Access

  • Integrated development environment (IDE) for R. RStudio local GUI and RStudio Server is web-based.
  • User access to RStudio Server on HPCC

Some useful RStudio shortcuts:

  • Ctrl+Enter: send code to R console
  • Ctrl+Alt+Enter: send code to terminal
  • Ctrl+Shift+C: comment/uncomment
  • Ctrl+1/2: switch window focus

Nvim-R-Tmux: Terminal-based R Environment

Advantages of Command-line UI

  • Knowledge of command-line interface is essential for working on a computer cluster efficiently
  • Main advantage: language agnostic approach that works with most computer languages
  • Users of Emacs may want to consider using ESS instead


  • Background
  • Neovim-based IDE for R
  • Conclusions
  • References

Introduction to Nvim-R-Tmux

  • Note: the content on the following slides is also available in this tutorial section here.
  • The examples are assuming that users are logged into their HPCC cluster account, or are working on a system where vim/nvim is accessible via a terminal.
  • The following introduces Nvim-R combined with Tmux.
  • Similar instructions are available in HPCC’s Nvim-R-Tmux tutorial here.
  • Note: Nvim-R and Tmux are two separate tools that can be used independently or in combination, and both are useful for remote terminal work.
  • For simplicity, some of the following examples use Nvim-R without Tmux. Once users know the basics of both then it is trivial to combine them as needed.

Vim/Nvim Basics

The following opens a file (here myfile.txt) with nvim (or vim). This can be a new file or an existing one.

nvim myfile.txt # for neovim (or 'vim myfile.txt' for vim)


In Vim/Nvim there are three main modes: normal, insert and command mode. The most important commands for switching between the three modes are:

  • i: switches from the normal to the insert mode. The latter is used for typing.
  • Esc: switches from the insert mode back to the normal mode.
  • :: starts the command mode (from normal mode) at the bottom of the terminal window.

The cursor is moved with the arrow keys. In Nvim one can also enable mouse-based movements of the cursor. Fn Up/Down allows to page. In the following, all commands starting with : need to be typed in the command mode. All other commands are typed in the normal mode after pushing the Esc key.

[ Scroll down to continue ]

Important modifier keys to control Vim/Nvim

  • :w: saves changes to file. If in editing mode, Esc needs to be pressed first.
  • :q: quits file that has not been changed; use q! to quit file without saving changes.
  • :wq: saves and quits file

Useful resources for learning Vim/Nvim

Quick Nvim-R Demo (details on next slides)

To try out the following instructions, users want to log into their HPCC account via ssh, and then preferentially connect to a node by initializing an interactive srun session. The latter mimics the best practices for a real workflow but is not necessary for this basic exercise. If Nvim-R is not installed in a user’s account yet, then configure it with the Install_Nvim-R_Tmux command as outlined here.

srun --x11 --partition=short --mem=2gb --cpus-per-task 4 --ntasks 1 --time 1:00:00 --pty bash -l
  • Under --partition it is important to assign the name of a partition a user has access to
    • Most users have access to: short, batch, intel and highmem
    • Users of labs owning computer nodes also can access: <pi_name>lab
  • For more details on argument settings for srun, see here

Download R_for_HPC_demo.R or nvimr_demo.R file to you HPCC account as follows.

wget https://raw.githubusercontent.com/tgirke/GEN242/main/static/custom/slides/R_for_HPC/demo_files/R_for_HPC_demo.R
wget https://raw.githubusercontent.com/tgirke/GEN242/main/static/custom/slides/R_for_HPC/demo_files/nvimr_demo.R

[ Scroll down to continue ]

Open R_for_HPC_demo.R or nvim_demo.R with nvim. The content of R_for_HPC_demo.R file is shown in the following code block. Next, initialize a Nvim-connected R session with \rf, and then execute the code by pressing the space bar on your keyboard.

write_tsv(iris, "iris.txt") # Creates sample file                                                                                                                             
read_tsv("iris.txt") %>% # Import with read_tbv from readr package                                                                                                            
    as_tibble() %>%                                                                                                                                                           
    group_by(Species) %>%                                                                                                                                                     
    summarize_all(mean) %>%                                                                                                                                                   
    reshape2::melt(id.vars=c("Species"), variable.name = "Samples", value.name="Values") %>%                                                                                  
    ggplot(aes(Samples, Values, fill = Species)) +                                                                                                                            
    geom_bar(position="dodge", stat="identity")

[ Scroll down to continue ]

If X11 is enabled in a user session then the above code will generate the following bar plot in a separate graphics window.