From RStudio to Remarkable: transform your R development with VS Code

biodiversityDS.
4 min readFeb 22, 2024

--

I’m a data scientist working on unraveling the patterns and drivers of global marine biodiversity. I recently switched from RStudio to Visual Studio Code (VS Code) for R development to enhance my coding experience in two major aspects:

Cross-Language Support: VS Code’s ability to support multiple programming languages out of the box, including R, Python, JavaScript, and more, allows developers to work on multi-technology projects seamlessly. This feature is particularly beneficial for me, as I work with different languages and frameworks, reducing the need to switch between tools.

GitHub Copilot Integration: The integration with GitHub Copilot transforms coding in VS Code by providing AI-powered code completions. This feature accelerates my development processe, helps in reducing coding errors, and encourages the exploration of new coding solutions through intelligent, context-aware suggestions.

This guide will walk you through setting up VS Code for an enhanced R programming experience. I’ll cover the installation of necessary extensions, integration of radian as an R console, inclusion of essential packages, and configuration of global properties for optimal R development.

R development with VS Code.

Step 1: Installing the R Extension

First and foremost, to start using R in VS Code, you need to install the R extension. This extension provides rich support for the R language, including features like syntax highlighting, code formatting, and more. Here’s how to install it:

1.1. Open VS Code.

1.2. Navigate to the Extensions view by clicking on the square icon on the sidebar or pressing Ctrl+Shift+X (Cmd+Shift+X on the Mac).

1.3. Search for “R” in the extensions marketplace.

4. Find the R extension by Yuki Ueda or REditorSupport (identified by its logo and author name) and click Install.

Step 2: Integrating Radian

Radian is an alternative console for R with features like syntax highlighting and auto-completion. To integrate radian with VS Code, ensure R and Python are installed on your system and install radian by running in your terminal the following command.

2.1. Install radian.

pip3 install radian

Configure VS Code to use radian by setting the path to the radian executable in your settings.json. On a Mac, this is typically /usr/local/bin/radian. You can access settings.json by pressing Cmd+Shift+P on Mac or Ctrl+Shift+P on Windows/Linux, typing “Open Settings (JSON)”, and pressing Enter.

2.2. Copy the following code into settings.json.

{
"r.rterm.mac": "/usr/local/bin/radian"
}

Step 3: Installing Essential Packages

For an enhanced development experience, install the languageserver, httpgd, and lintr packages in R. These packages provide language support, graphics display capabilities, and linting for R scripts, respectively.

3.1. Install them by running the following commands in your R console.

install.packages("languageserver")
install.packages("httpgd")
install.packages("lintr")

Step 4: Configuring Linters and Global Properties

An integral part of setting up VS Code for R development is fine-tuning the behavior of the lintr package, which plays a crucial role in maintaining high code quality and adherence to coding standards. By customizing the .lintr configuration, developers can control which linting rules are enforced, tailoring the development environment to their preferences or project-specific guidelines.

Enhance your R programming experience in VS Code by tweaking some settings in your settings.json file. You can access settings.json by pressing Cmd+Shift+P on Mac or Ctrl+Shift+P on Windows/Linux, typing “Open Settings (JSON)”, and pressing Enter.

4.1. Add the following configurations to optimize R script editing, plotting, and formatting:

{
"r.bracketedPaste": true,
"r.removeLeadingComments": true,
"r.plot.useHttpgd": true,
"editor.wordWrap": "wordWrapColumn",

"[r]": {
"editor.defaultFormatter": "REditorSupport.r"
},

"workbench.colorCustomizations": {
// "editorError.foreground": "#00000000", // Red Squiggly, I suggest not to change this one…
// "editorWarning.foreground": "#00000000", // Yellow Squiggly, I suggest not to change this one…
"editorInfo.foreground": "#00000000", // Blue Squiggly, you could even change it yo something almost completely transparent so it doesn’t bother you as much…
}

}

These settings enable bracketed paste for more efficient console use, remove leading comments when executing code, utilize httpgd for plotting, and set the default formatters for R, ensuring your code is always neat and readable.

Conclusion

Migrating from RStudio to VS Code for R development not only opens up new possibilities for enhancing your development environment but also requires some adjustments to tailor the experience to your preferences.

By following the above steps, you’ve now equipped VS Code with powerful tools and configurations to supercharge your R programming. With the R extension, radian, essential packages, and tailored settings, you’re all set to enjoy a streamlined, productive coding experience in R. Whether you’re analyzing data, creating visualizations, or developing statistical models, VS Code is now a formidable ally in your R programming endeavors. Happy coding!

--

--

biodiversityDS.
biodiversityDS.

Written by biodiversityDS.

Hi!! I’m Jorge Assis, a Data Scientist, Marine Ecologist, Climate Change Analyst, R and Python Developer based in Portugal [biodiversitydatascience.com]

Responses (1)