Introduction
RStudio has traditionally been the preferred environment for R programming due to its extensive support for data analysis and interactive tasks. However, Visual Studio Code (VSCode) offers a more flexible, multi-language IDE that’s customizable through settings and a rich ecosystem of extensions.
By using the vscode-R extension, VSCode provides comprehensive support for R programming, combining core R features with flexibility to work on multi-language projects or remote servers.
This article guides you through setting up your VSCode environment for efficient R programming.
Essential Tools for R Programming in VSCode
The following tools and packages are essential for an optimized R environment in VSCode:
- VSCode: Modern IDE supporting multiple languages.
- vscode-R: Provides syntax highlighting, data viewer, workspace viewer, and integration with R Markdown.
- languageserver: Offers intelligent coding features such as auto-completion, diagnostics, and documentation tooltips.
- radian: Enhanced R console with syntax highlighting and advanced completion.
- vscode-R-debugger: Adds powerful debugging capabilities, including breakpoints and step-by-step execution.
- httpgd: Interactive graphics device for enhanced plot visualization directly within VSCode.
- rmarkdown: Create reproducible reports and documentation.
- Pandoc (optional): Enables documentation preview features within VSCode.
Step-by-Step Guide for Setting Up R in VSCode
Follow these clear steps to configure your R environment in VSCode effectively:
Step 1: Install R and VSCode
- Install R: Download the latest version from the CRAN website and follow the installation guide.
- Install VSCode: Download from the official VSCode website suitable for your operating system (Windows, macOS, Linux).
Step 2: Install vscode-R Extension
- Open VSCode and go to the Extensions tab (
Ctrl+Shift+X
). - Search for
REditorSupport.r
and install the extension.
Important OS-specific notes:
- Linux/macOS: Default settings work with CRAN installations. For custom paths, update
r.rterm.linux
orr.rterm.mac
. - Windows: Ensure the registry option is enabled during R installation. Otherwise, manually configure
r.rterm.windows
in VSCode settings.
Step 3: Install languageserver R Package
Install from your R console:
install.packages("languageserver")
Windows users should first install Rtools
.
Step 4: Configure Radian for Interactive R Terminal
radian
enhances your R terminal experience:
- Install using Python’s pip:
pip install -U radian
- Set radian as your default R terminal in VSCode settings (
Ctrl+,
):
"r.rterm.windows": "C:\\Python\\Scripts\\radian.exe",
"r.rterm.mac": "/usr/local/bin/radian",
"r.rterm.linux": "/usr/bin/radian"
Adjust paths accordingly.
Step 5: Install Additional Tools
- rmarkdown: Generate reproducible reports:
install.packages("rmarkdown")
- Pandoc (optional): Recommended for enhanced documentation previews. Download and install from the official site.
Step 6: Set Up R Debugger in VSCode
Install debugging tools:
- Install VSCode extension: R Debugger.
- Install the corresponding R package:
install.packages("remotes")
::install_github("ManuelHentschel/vscDebugger") remotes
Step 7: Enhanced Plot Viewer with httpgd
To improve your plotting experience, install and configure httpgd
:
install.packages("httpgd")
Activate it in VSCode settings (Ctrl+,
):
"r.plot.useHttpgd": true
Recommended VSCode Settings for R
Optimize your workflow by adding these settings in your settings.json
file:
{
"r.bracketedPaste": true,
"r.sessionWatcher": true,
"editor.formatOnSave": true,
"r.alwaysUseActiveTerminal": true
}
Learn more recommended configurations in our dedicated guide: Recommended VSCode Configurations for R Programming.
Conclusion
By following this guide, you’ve set up a robust and efficient R programming environment in VSCode. This setup combines the flexibility of VSCode with the powerful capabilities of R-specific tools, significantly enhancing your coding experience.
References & Further Reading
Explore More Articles
Here are more articles from the same category to help you dive deeper into the topic.
Reuse
Citation
@online{kassambara2025,
author = {Kassambara, Alboukadel},
title = {Setting {Up} {Your} {R} {Environment} in {VSCode}},
date = {2025-03-23},
url = {https://www.datanovia.com/learn/tools/r-in-vscode/setting-up-r-environment-in-vscode.html},
langid = {en}
}