How to Use R in VSCode for Data Science

Summarize this article with:

RStudio works fine. But it is not the only option anymore.

Learning how to use R in VSCode opens up a flexible, multi-language IDE with better customization, GitHub Copilot support, and a massive extension ecosystem.

Many R programmers stick with RStudio because setting up Visual Studio Code for R feels complicated. It does not have to be.

This guide walks you through the complete setup process, from installing the vscode-R extension to configuring radian terminal and httpgd for plots.

You will learn how to run R scripts, enable code completion with languageserver, and configure your R development environment in under 30 minutes.

Eight steps. No guesswork.

How to Use R in VSCode

maxresdefault How to Use R in VSCode for Data Science

Using R in VSCode is the process of configuring Visual Studio Code to run R scripts, execute code, and display outputs through extensions and packages.

Users need this when they want a multi-language development environment, GitHub Copilot integration, or customization beyond what RStudio offers.

This guide covers 8 steps requiring 15 to 30 minutes and basic familiarity with R programming and code editors.

Prerequisites

Before you start, make sure you have these ready:

  • R version 4.0.0 or later installed on your system
  • Visual Studio Code version 1.70 or later
  • Python 3.7 or later (needed for radian terminal)
  • Administrator access for software installation
  • Windows, macOS, or Linux operating system

Total setup time runs between 15 and 30 minutes depending on your internet speed and familiarity with terminal commands.

Step One: How Do You Install R on Your Computer?

Download R from CRAN at r-project.org and run the installer for your operating system.

Action:

  1. Go to https://cran.r-project.org/ and select your OS
  2. Windows users: click “base” then “Download R-4.x.x for Windows”
  3. macOS users: download the .pkg file matching your chip (Intel or Apple Silicon)
  4. Linux users: follow the instructions for your distribution

Windows users should check “Save version number in registry” during installation.

This lets the R extension find the executable automatically.

Purpose: The R extension needs R installed locally to execute scripts and provide language features.

Step Two: How Do You Install the R Extension in VSCode?

Open VSCode, go to Extensions (Ctrl+Shift+X), search for “R” by REditorSupport, and click Install.

Action:

  1. Click the Extensions icon in the left Activity Bar (four squares icon)
  2. Type “R language” in the search box
  3. Select R by REditorSupport from the results
  4. Click the blue Install button

This extension provides syntax highlighting, code completion, and workspace viewer features.

You will see an R icon appear in your Activity Bar after installation completes.

Purpose: The vscode-R extension is the foundation for all R language support in Visual Studio Code.

Step Three: How Do You Install the languageserver Package?

Open an R console and run install.packages("languageserver") to enable code intelligence features.

Action:

  1. Open the terminal in VSCode using Ctrl+ (backtick)
  2. Type R to start an R session
  3. Run: install.packages(“languageserver”)
  4. Select a CRAN mirror when prompted
  5. Wait for installation to complete

The languageserver package powers autocompletion, function signatures, and go-to-definition.

Without it, you only get basic syntax highlighting.

Purpose: This package enables the R Language Server Protocol, which connects VSCode to R’s code intelligence features.

Step Four: Where Do You Configure the R Path in VSCode Settings?

Open Settings (Ctrl+,), search for “r.rpath”, and enter the path to your R executable.

Action:

  1. Press Ctrl+, to open Settings (or Cmd+, on macOS)
  2. Search for r.rpath
  3. Enter the path for your operating system:
  • Windows: C:Program FilesRR-4.x.xbinR.exe
  • macOS: /usr/local/bin/R
  • Linux: /usr/bin/R

If the path is wrong, VSCode cannot start R sessions or execute code.

Purpose: VSCode needs the exact location of R to launch terminals and run scripts.

Step Five: How Do You Install and Configure Radian Terminal?

Install radian using pip, then configure VSCode to use it as the default R terminal.

Action:

  1. Open a terminal and run: pip install radian
  2. Find radian’s path: where radian (Windows) or which radian (macOS/Linux)
  3. Open settings.json in VSCode using Ctrl+Shift+P, then type “Open Settings JSON”
  4. Add the radian path to r.rterm.windows, r.rterm.mac, or r.rterm.linux
  5. Set “r.bracketedPaste”: true

The radian terminal provides syntax highlighting, multiline editing, and autocompletion in the console.

Standard R terminal lacks these features.

Purpose: Radian makes the interactive R console much more usable with modern terminal features.

Step Six: How Do You Install httpgd for Plot Viewing?

Run install.packages(“httpgd”) in R to enable the interactive plot viewer inside VSCode.

Action:

  1. Start an R session in VSCode terminal
  2. Run: install.packages(“httpgd”)
  3. Open VSCode Settings and search for “r.plot.useHttpgd”
  4. Check the box to enable httpgd

The httpgd package renders plots as SVG graphics in a dedicated viewer panel.

You can resize plots dynamically, something RStudio users expect.

Purpose: Without httpgd, plots open in external windows or display as static images.

Step Seven: How Do You Run R Code in VSCode?

Select code and press Ctrl+Enter to send it to the R terminal for execution.

Action:

  1. Create a new file with .R extension
  2. Write R code in the editor
  3. Place cursor on a line or select multiple lines
  4. Press Ctrl+Enter (Cmd+Enter on macOS) to execute

The R terminal must be running. Click “Not Attached” in the status bar if you see it.

Use Ctrl+Shift+S to run the entire script at once.

Purpose: Keyboard shortcuts let you execute R code without switching between editor and terminal.

Step Eight: How Do You Configure Additional Settings for R in VSCode?

Enable session watcher and code linting in settings for a complete R development environment.

Recommended settings for settings.json:

` { "r.bracketedPaste": true, "r.sessionWatcher": true, "r.plot.useHttpgd": true, "r.lsp.diagnostics": true, "r.alwaysUseActiveTerminal": true } `

Install the lintr package in R for code style checking: install.packages(“lintr”)

The R Debugger extension adds breakpoint support if you need debugging capabilities.

Purpose: These settings enable workspace viewer, variable inspection, and code diagnostics.

Verification

Test your setup by creating a simple R script and checking each feature works correctly.

Verification steps:

  1. Create a file called test.R
  2. Add this code:

` x <- 1:10 plot(x, x^2) print("Setup complete") `

  1. Press Ctrl+Enter to run each line
  2. Check that:
  • Code executes in the R terminal
  • Plot appears in the plot viewer
  • Variables show in workspace viewer (R icon in sidebar)
  • Autocompletion works when typing

If all four checks pass, your R environment in VSCode is ready.

Troubleshooting

Issue: R Terminal Not Starting

Solution: Verify the R path in settings. Open terminal, type R –version to confirm R is accessible from command line.

Windows users may need to add R to their system PATH environment variable.

Issue: Plots Not Displaying

Solution: Confirm httpgd is installed by running library(httpgd) in R.

Check that “r.plot.useHttpgd” is enabled in VSCode settings.

Issue: Autocompletion Not Working

Solution: The languageserver package may not be installed or loaded correctly.

Reinstall with install.packages(“languageserver”) and restart VSCode.

Issue: Code Not Executing with Keyboard Shortcut

Solution: The R terminal may not be attached to the session watcher.

Click “Not Attached” in the bottom status bar, or open a new R Terminal from the command palette.

Alternative Setup Methods

Basic Setup (without radian):

  • Time: 5 to 10 minutes
  • Complexity: Low
  • Best for: Users who do not have Python installed

Full Setup (with radian and httpgd):

  • Time: 15 to 30 minutes
  • Complexity: Medium
  • Best for: Users who want an RStudio-like experience

Choose Basic Setup if you only need to run simple R scripts occasionally.

Choose Full Setup if R is your primary language and you need data visualization.

Related Guides

FAQ on How To Use R In Vscode

Can I use R in VSCode?

Yes. Install the R extension by REditorSupport and the languageserver package in R. VSCode then supports syntax highlighting, code execution, debugging, and interactive plotting for R programming.

Is VSCode better than RStudio for R?

Depends on your needs. VSCode offers better multi-language support, more extensions, and GitHub Copilot integration. RStudio provides a simpler out-of-box R experience. VSCode requires more initial setup but offers greater customization.

How do I run R code in VSCode?

Select your code and press Ctrl+Enter (Cmd+Enter on macOS). This sends the selected lines to the R terminal for execution. Use Ctrl+Shift+S to run the entire R script at once.

What extensions do I need for R in VSCode?

The R extension by REditorSupport is required. Optional but recommended: R Debugger for breakpoints and debugging. Install languageserver and httpgd packages in R for code intelligence and plot viewing.

How do I view plots in VSCode with R?

Install the httpgd package using install.packages(“httpgd”) in R. Enable "r.plot.useHttpgd" in VSCode settings. Plots render in a dedicated viewer panel with resize support.

Why is my R terminal not working in VSCode?

Check your R path in VSCode settings under “r.rpath”. Verify R is installed by running R –version in your system terminal. Windows users may need to add R to the PATH environment variable.

How do I install R packages in VSCode?

Open an R terminal in VSCode and run install.packages(“packagename”). Works exactly like RStudio. Select a CRAN mirror when prompted. Packages install to your default R library location.

Can I use R Markdown in VSCode?

Yes. Install the R Markdown extension or Quarto extension for full support. You can render .Rmd files using rmarkdown::render() in the terminal. Viewing Markdown in VSCode works with live preview.

How do I enable autocomplete for R in VSCode?

Install the languageserver package in R using install.packages(“languageserver”). The R extension uses this for autocompletion, function signatures, and go-to-definition. Restart VSCode after installation.

How do I debug R code in VSCode?

Install the R Debugger extension from the marketplace. Set breakpoints by clicking the line number margin. Launch the debugger using the Run menu. Step through code, inspect variables, and evaluate expressions.

Conclusion

You now know how to use R in VSCode with a complete setup that rivals RStudio.

The R extension by REditorSupport, combined with radian and httpgd, creates a proper R programming environment inside a modern code editor.

Your setup includes syntax highlighting, code intelligence, interactive plotting, and workspace viewer. Everything you need for statistical programming and data visualization with ggplot2 or base R.

VSCode also handles R Markdown and Quarto documents. Git integration works out of the box. GitHub Copilot can assist with your R code if you have access.

The initial configuration takes effort. But you end up with a flexible, customizable integrated development environment that grows with your R projects.

Start with a simple script. Build from there.

50218a090dd169a5399b03ee399b27df17d94bb940d98ae3f8daff6c978743c5?s=250&d=mm&r=g How to Use R in VSCode for Data Science
Related Posts