Skip to content
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.
/ RinVSC Public archive

How to establish R workflow in Visual Studio Code

Notifications You must be signed in to change notification settings

EvoLandEco/RinVSC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 

Repository files navigation

R workflow in Visual Studio Code

image

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.

I. Preparation

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.

II. Installing extensions

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 for VS Code.
  • R LSP Client It provides powerful R language support including formatting and debugging.
  • R Debugger It provides R debugging capabilities to VS 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.

III. Installing an alternative R console

image

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.

IV. Setting up VS Code and installing packages

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 on Windows, also note that there are two text boxes for you, you must enter the path of radian.exe into the one accepting radian
  • Enable R session watcher.
  • Press Ctrl + Shift + P, enter create R terminal, then press Enter. Your radian enhanced R 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 for R 4.1.0, so you need to compile and install using devtools.
# 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.

V. Tricks and workarounds

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 that R 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

VI. Examples

Theme, R extension, GitLens, radian terminal, UI layout

image

Source control, httpgd plot viewer, R language server

image

About

How to establish R workflow in Visual Studio Code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published