Setup R with Visual Studio Code
This setup guides you through setting up R
in VSCode
so you can use it on dancmpn01fl
and dancmpn02fl
computing nodes.
Info
The original RStudio server is using 4.0.5 version. If you want to stick this version, make sure to specify it when loading modules.
Why do you need this?
Because RStudio server sucks when you don't have a license and our place, so alternative it is. Also, VSCode has a bunch of plugins.
Setting up Remote Tunnels
Warning
In this example we use version R/4.2.1. If you want to use a different one change the R version!
Requirements
- VSCode
- Terminal
Setting up first time
- Login to head node:
ssh $USER@danhead01fl.unicph.domain
- Start a new tmux session:
tmux new -s rstudio
- Start a new job:
srun -c 2 --mem=30gb --time=0-4:00:00 --pty bash
- Load modules:
module load vscode_cli gcc/11.2.0 R/4.2.1 quarto
- Run command:
code tunnel
- Choose
Microsoft account
when asked how you would like to log in to VScode - Open the link from terminal and paste the CODE
- Login with your KU credentials
- Go back to terminal and wait
- Hit ENTER on questions about tunnel name
- If everything went well you should see some random messages about port forwarding
- Choose
- Go to your VSCode and on the left panel search for
Remote Explorer
- Click
Sign in to the tunnels registered with Microsoft
- You should see
dancmpn01flunicphdom
ordancmpn02flunicphdom
- You should see
- Move cursor on it and click the
->
- Install extension Remote Tunnels
To use R
, install additional packages by clicking Extensions
in the left panel.
Search for packages:
- R
-
Next, top panel lick
View
->Terminal
-> WriteR
and hit ENTER install.packages("languageserver")
- If it asks to install to stuff to other directory type
YES
then hit ENTER - When asking about mirror type
30
(Denmark servers to download packages)
- If it asks to install to stuff to other directory type
install.packages("httpgd")
q()
to get out- Top left panel:
Code
->Settings
->Settings
- Type in search
r.plot.useHttpgd
- Tick the box if it is not checked
- Type in search
If everything went well, you should be able to do this. If not, you know what to do.
I already did the setup, I want my R again
- Login to head node:
ssh $USER@danhead01fl.unicph.domain
- Start a new tmux session:
tmux new -s rstudio
- Start a new job:
srun -c 2 --mem=30gb --time=0-4:00:00 --pty bash
- Load modules:
module load vscode_cli gcc/11.2.0 R/4.2.1 quarto
- Run command:
code tunnel
- Go to your VSCode and on the left panel search for
Remote Explorer
- Click
dancmpn01flunicphdom
ordancmpn02flunicphdom
Admins: How to install
Creating module
curl -Lk 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64' --output vscode_cli.tar.gz
tar -xf vscode_cli.tar.gz
Known issues
VSCode can be installed as a server code-server
, however it is not possible
to listen on the port when on computing node. This works only in the case of
dangpu01fl
.
Error when trying to do reverse ssh:
VSCode code-server
is an alternative to code tunnel
that consists of running
code-server on a compute node and
accessing it via a web browser using reverse ssh
tunnel.