Visual Studio Code is a free, open-source and multi-platform code editor. Its marketplace offers rich extensions to enhance its functionality. R
workflow can be easily established in VS Code
on Windows
, Mac OS
and Linux
.
To establish a smooth R
workflow, you need to install R Base
, R Tools
, VS Code
and Python
. Python
is needed because I will introduce an enhanced R console based on it.
- R Base Get the latest precompiled binary distribution.
- R Tools Get the latest version.
- VS Code Get the latest version for your platform.
- Python Get the latest release.
You can find the Extensions Tab at the left-most panel in VS Code
. Click on it and then search and install the following two extensions:
- R It provides basic
R
support forVS Code
. - R LSP Client It provides powerful
R
language support including formatting and debugging. - R Debugger It provides
R
debugging capabilities toVS Code
.
I strongly recommend you to also install the following extensions for the marketplace:
- Bracket Pair Colorizer It allows matching brackets to be identified with colours. This is quite useful in coding.
- GitHub Pull Requests and Issues It allows you to review and manage Github pull requests and issues.
- GitLens — Git supercharged It "helps you to visualize code authorship at a glance via Git blame annotations and code lens, seamlessly navigate and explore Git repositories, gain valuable insights via powerful comparison commands, and so much more".
Feel free to find your favourite themes and extenstions in the marketplace, VS Code
is highly customisable. The following theme is my favourite:
- One Dark Pro It is one of the most installed themes for
VS Code
.
If you get bored with R
console, radian provides you with an alternative choice. It has multiline editing and rich syntax highlight, along with many other enhancements. It needs Python
to work.
You can easily install radian
by pip
# install released version
pip install -U radian
# or the development version
pip install -U git+https://github.com/randy3k/radian
And if you use conda
,
conda install -c conda-forge radian
For more features and options, please visit radian.
To use radian
, you need to set up the R extension manually. Switch to the Extensions Tab in VS Code
, find R, and then right click to access its extension settings.
- Enter R path for your platform. Note that here we use
radian
's path instead. If you are onWindows
, also note that there are two text boxes for you, you must enter the path ofradian.exe
into the one acceptingradian
- Enable R session watcher.
- Press
Ctrl + Shift + P
, entercreate R terminal
, then pressEnter
. Yourradian
enhancedR
console will open.
The extensions relies on the following packages, you need to install them manually:
- httpgd It provides a better user experience when dealing with R graphic.
- languageserver
R LSP Client
relies on it. - vscDebugger
R Debugger
relies on it, there is no release forR
4.1.0, so you need to compile and install usingdevtools
.
# dependencies are also included
install.packages(c("R6", "jsonlite", "lintr", "languageserver", "httpgd", "rlang"))
devtools::install_github("ManuelHentschel/vscDebugger")
The last step, put the following option in ~/.Rprofile
to enable httpgd graphics device:
options(vsc.use_httpgd = TRUE)
R
workflow in VS Code
is now fully functional. You can try some demos.
The developers of the extensions are actively updating and implementing new features, and they are planning to integrate all these extensions to make installation easier for all users. Visit vscode-r wiki for more tricks and instructions.
- Plot something, the
httpgd
plot viewer will appear. - You can find workspace viewer and help pages in the R Tab. The workspace viewer is not as powerful as that in
R Studio
now, but an update is coming. VS Code
UI is much more flexible thatR Studio
, right click on all the panels and tabs to see what you can do.- Always remember to hit
Tab
when you are typing something in radian (R console) to trigger auto-completion
Last Update: 02/07/2021
Theme, R extension, GitLens, radian terminal, UI layout
Source control, httpgd plot viewer, R language server