Setting up VS Code and R for remote development
RStudio is my almost always my go-to IDE for using R. However, although it is possible to use R through a remote machine through RStudio, many features are lost, such as the workplace viewer. To use remote R through RStudio, start a terminal session, log into the remote environment through SSH, and activate R. Then use control + option + enter
to dispatch lines of code, instead of control + enter
.
VSCode in general is much better suited for integrated remote developmnet, and when set up can be very seamless. I’ll be exploring how well this can be extended to R. I’ll also need to use R within a conda environment so additional work is needed.
The official documentation helps get us started.
- Ensure that you have a conda environment with R installed
- Install
languageserver
usinginstall.packages("languageserver")
in the loaded conda environment R. Alternatively installlanguageserver
using conda-forge:conda install -c conda-forge r-languageserver
- Install the R extension for VS Code onto the remote server
- Install radian, ideally by using conda-forge
conda install -c conda-forge radian
- This forum post has some useful tips, but when loading radian I was not able to get it to use the conda environment R. This can be fixed by using the following configartion for the R extension on the remote host:
{
"r.rpath.linux": "path_to_conda/.conda/envs/env_name/bin/R",
"r.rterm.linux": "path_to_conda/.conda/envs/env_name/bin/radian",
"r.rterm.option": [
"--no-save",
"--no-restore",
"--r-binary=path_to_conda/.conda/envs/env_name/bin/R"
]
}
This forces radian to use the conda R on load. If unsure as to the above paths, make sure that conda environment is activated, and use:
which R
which radian
- Now we can finally start an R session using the command pallet (
command + shift + p
) andCreate R terminal
and we should be in the correct version. Workspace viewer, linting, etc, should work.
I’ll update this post if I come across any limitations or a better way to do this.