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:

Open VS Code.

Navigate to the Extensions view by clicking on the square icon on the sidebar or pressing Ctrl+Shift+X.

Search for “R” in the extensions marketplace.

Find the R extension by Yuki Ueda (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.

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. Copy the following code.

{
"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. 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.

One common requirement is to adjust the linting rules for line length. In statistical programming, long lines of code can occur, especially in comments or when using long strings. To prevent lintr from flagging these as issues and to avoid the underlining of long sentences in your R scripts, you can disable the line_length_linter. To customize your .lintr file to ignore line length warnings, add the following configuration.

linters: with_defaults(line_length_linter = NULL)

Further enhance your R programming experience in VS Code by tweaking some settings in your settings.json file. 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"
}

}

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.

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