January 20, 2025
3 mins read

Tutorial: How to Use R in Visual Studio Code ( VS Code )

VSCode VS Code

Visual Studio Code (VS Code) is a source code editor that is popular for its versatility, lightness, and customizability. If you work with R and want to use VS Code as your development environment, this tutorial will walk you through the step-by-step setup of VS Code so you can run R code efficiently.

Step 1: Install R

Before using R in VS Code, make sure you have R installed on your computer. If you don’t already have it, follow these steps:

Follow the instructions to install R on your computer.

  1. Go to the official R website and download the appropriate version for your operating system (Windows, macOS or Linux).
  2. Follow the instructions to install R on your computer.

Step 2: Install Visual Studio Code

If you don’t have VS Code installed, follow these steps:

  1. Install VS Code by following the instructions provided.
  2. Go to the Visual Studio Code download page and download the version for your operating system.

Step 3: Install the R extension in Visual Studio Code

To work with R in VS Code, you need to install an extension that allows you to integrate R functions into the editor. Here’s how:

  1. Open Visual Studio Code.
  2. Go to the Extensions Marketplace by clicking the extensions icon in the left sidebar or by pressing Ctrl + Shift + X.
  3. Look for the extension called R developed by Yuki Ueda. This extension provides you with basic functions such as running R scripts.
  4. Click Install.

Step 4: Configure R in VS Code


Once the R extension is installed, you need to make sure that VS Code recognizes the location of R on your system. 

1. Open the VS Code settings (you can click the gear icon in the bottom left corner and select Settings, or press Ctrl + ,). 

2. In the settings search bar, type “r.rterm.windows”, “r.rterm.mac”, or “r.rterm.linux” depending on your operating system. 

3. Enter the path to the R executable file on your system. For example:   On Windows, it’s usually in:  “C:\\Program Files\\R\\R-x.x.x\\bin\\R.exe”   On macOS and Linux, you can simply type “R” if you already have R set up on your terminal. 

4. Save your settings.

    Step 5: Install additional extensions for a better experience

    If you want to improve your workflow with R in VS Code, you can install some additional extensions:

    1. R LSP Client: Provides code autocomplete, error highlighting, and debugging functions. To install this extension:
      1. Open the Extensions Marketplace.
      1. Search for R LSP Client and click Install.
      1. To make it work, you also need to install languageserver, an R package. You can do this by running this command in the R console: install.packages("languageserver")
    2. Rainbow CSV: This extension helps visualize CSV files with different colors for columns, which is useful if you work with tabular data.
    3. Bracket Pair Colorizer 2: Makes the pairing of brackets and parentheses clearer by coloring them differently.

    Step 6: Run R code in Visual Studio Code

    Once everything is set up, you can start writing and running R code.

    1. Create a file with the .  A. To do this, select File > New File and save it as a script. A.
    2. Type your R code into the file. For example: print("Hello, R from VS Code!")
    3. To run the code, select the line you want to run and press Ctrl + Enter. This will send the code to the R console that will open in the VS Code terminal.

    Step 7: Use an interactive environment with R (Radian)

    To enhance the R console in VS Code, you can use Radian, which is an alternative interpreter for R with additional features such as code autocomplete and improved colors. To install it:

    1. Open the terminal on your computer.
    2. Install Radian using pip, the Python package manager: pip install radian
    3. Then, set VS Code to use Radian instead of the default R console. Go to the settings (Ctrl + ,) and search for "r.rterm.windows", "r.rterm.mac" or "r.rterm.linux" and change the path to radian or the path to the radian executable.

    Step 8: Debugging and Using Graphics in VS Code

    • Debugging: If you have the R LSP Client extension installed, you can use debugging features as breakpoints to inspect the state of your code.
    • Graphics: Graphics generated with R will appear in a separate window, but if you want them to appear within VS Code, you can use the R Plot Viewer extension.

    Step 9: Customize the environment

    You can customize the development environment by adjusting themes, fonts, and keyboard shortcuts to make your experience more enjoyable and efficient. Find the settings in the Settings menu  (Ctrl + ,).

    VS Code

    Avelino Dominguez

    Biologist - Teacher - Statistician #SEO #SocialNetwork #Web #Data ♟Chess - Galician

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    visual code studio
    Previous Story

    Tutorial: Cómo usar R en Visual Studio Code

    días festivos bolsa estados unidos 2025
    Next Story

    Días festivos de la bolsa de valores de Estados Unidos en 2025

    Top

    Don't Miss

    visual code studio

    Tutorial: Cómo usar R en Visual Studio Code

    Visual Studio Code (VS Code) es…
    números primo primo

    Verificar si un número es primo o no utilizando Python

    Este artículo explica cómo saber si…