Skip to content

HPC and R VScode

Paul Sastourné-Haletou edited this page Nov 27, 2024 · 2 revisions

Setting Up R in VSCode

Author: Paul

Date: 11/27/24

Description

This guide explains how to set up and use R in VSCode while connecting to an HPC environment.


1. Prerequisites

Install the R VScode extension in VSCode: https://code.visualstudio.com/docs/languages/r


2. R extension Settings:

Update R terminal settings:

Screenshot 2024-11-27 at 1 27 07 PM

Define R path:

Update the path directly in the R extension settings. Make sure you are editing the settings for your remote VSCode instance, as shown at the top of the screenshot:

Screenshot 2024-11-27 at 1 23 58 PM

Alternatively, update the .vscode/settings.json file:

{
    "r.rterm.linux": "/path/to/R",
    "r.lsp.path": "/path/to/R"
}

3. Link Your .Rprofile:

Add the following lines to .Rprofile:

Sys.setenv(TERM_PROGRAM = "vscode")
source("/path/to/your/.vscode-R/init.R")

4. Activate your Conda environment and start R::

conda activate r_env
R

Optional 5. Attach VSCode to R Session:

.vsc.attach()

6.Tips

** Use tmux for Persistent Sessions: **

  1. Create a new tmux session:

    tmux new -s r_session
  2. List all sessions:

    tmux ls
  3. Reattach to a session:

    tmux attach -t r_session

Ruggles Lab Wiki

Quick Links

Clone this wiki locally