A fresh start for R in VSCode
Setting up Visual Studio Code for R development 🤑
Why am I writing this article?
As a data science major, most of my work with data-science (university or side-project) happens with R and Python. I write R in the traditional R console while all my other projects are done in VSCode. So I wanted to add R to my VSCode workspace.😉
When I searched the internet on how to do that, to my awe there was no article or YouTube video which tells how. I only found one article by Ken Run in which he describes his story and recommends his tools but not on how we could set up the environment.( Also many errors popped up while doing it his way )😓
So I searched the Internet and Stack Overflow about this and I wanted to write about it so anyone who is looking for instructions, can find it right away.🥳😎
Why VSCode?
- VSCode has support for most of the popular languages😍
- The community is huge and has plugins for every kind of language💖
- It has integrated terminal for faster development and takes less storage and has low memory footprint. It is identical to an IDE with the correct plugins plus I didn’t want to install R Studio🙂
What do you need?
- VSCode : A text editor my Microsoft
- R Language: The traditional R run time given by CRAN
- VSCode R Extension by Yuki Ueda
- R LSP Client for VSCode by REditorSupport
- Radian : A 21st century R console.
How to setup?
Firstly run the following command in your traditional R console:
install.packages(“languageserver”)
Install the following extensions
- VSCode R Extension by Yuki Ueda
This extension integrates shortcuts and other key-bindings to run the code directly in the workspace or editor. You can view your environment and also see dataframes with a single click.
2. R LSP Client by REditorSupport
This extension provides linting, autocomplete and function signatures along with proper function definitions and information. This extension helps you autocomplete the function parameters by hinting the parameter names and types. It also gives intelligent suggestions on the scope of the variables in custom functions that you define.
3. Next run this command in the terminal to install radian. It is a python module which has better color scheme and representations for R outputs in console. It serves as an alternative to the R console.
pip install -U radian
4. Finally add these lines in the settings.json
of your editor
"r.bracketedPaste": true,"r.rterm.windows": "*Path to radian executable*", //Use this only for Windows "r.rterm.linux": "*Path to radian executable*", //Use this only for Linux"r.rterm.mac": "*Path to radian executable*", //Use this only for a Mac"r.lsp.path": "*Path to your R executable*","r.lsp.debug": true,"r.lsp.diagnostics": true,"r.rterm.option": ["--no-save","--no-restore","--r-binary=*Path to R executable*"],
That's it.🎉You have configured your VSCode to be a perfect IDE for R
Here is how my settings.json
looks😅
Here are some screenshots for demo🙂
I’ll keep updating this post for more relevant and latest features that will be added👍
Thanks for Reading ✌