Skip to content
English

Approaching Positron from VS Code for R

Positron is a polyglot IDE with great support for R. Because it’s similar in many ways to both VS Code and RStudio, it’s an excellent meeting point for those coming from either IDE. However, Positron is also different in many ways to both VS Code and RStudio, so the transition will come with some pain.

To reduce that pain and stay productive, you can taste Positron or start preparing for the transition with relatively small and few changes to your current workflow from the comfort of your favorite IDE.

This post targets a user like the one described by this story:

As someone working with R and used to VS Code, I want to know how to transition to Positron smoothly, so that I can more easily collaborate with colleagues coming from RStudio.

Positron

If you come from VS Code and a language other than R, then you may not know exactly what to expect from an IDE that supports R, so here is an overview of what Positron includes:

  • Tools for data science:
    • R console.
    • Ability to send R code from scripts to the console with ctrl+enter.
    • Panels to explore plots and data.
    • Support for Quarto.
  • Tools for software development:
    • Keyboard shortcuts for building R packages with devtools.
    • Support for Shiny.
    • Testing.
    • Tools for debugging R code.

You can enable RSdudio keyboard shortcuts, e.g.:

  • Send code to the R console: ctrl+enter

  • Restart R: ctrl+shift+0

  • Assign <-: alt+-

  • Pipe |>: ctrl+M

  • Develop R packages using the devtools workflow:

    • load_all(): ctrl+shift+L

    • test(): ctrl+shift+T

    • document(): ctrl+shift+D

    • check(): ctrl+shift+E

VS Code

One feature of VS Code is that it’s lean and extensible. By default it comes with nothing of what’s listed above, but these few extensions and keyboard shortcuts approximate Positron’s experience for R.

  • Extensions:

# Basic R support, e.g. send code to the R console with Ctrl+Enter 
code --install-extension reditorsupport.r
# Needs this R package
Rscript -e 'install.packages("languageserver")'

# Debug
code --install-extension rdebugger.r-debugger

# Test
code --install-extension hbenl.vscode-test-explorer
code --install-extension meakbiyik.vscode-r-test-adapter

# Shiny
code --install-extension posit.shiny

# Quarto
code --install-extension quarto.quarto


TODO: In the VS Code command-palette run r.debugger.updateRPackage

  • Shortcuts: Place your key bindings in this file to override the defaults: ~/.config/Code/User/keybindings.json

[
// BASIC R SUPPORT
    {
      // Create a new R terminal (similar to restarting R)
      "key": "ctrl+shift+0",
      "command": "r.createRTerm"
  },
    {
      // Assign
        "key": "alt+-",
        "command": "type",
        "args": { "text": " <- " },
        "when": "editorTextFocus && editorLangId == 'r'"
  },
  {
        // Pipe
        "key": "ctrl+shift+m",
        "command": "type",
        "args": { "text": " |> " },
        "when": "editorTextFocus && editorLangId == 'r'"
    },

  // R PACKAGE DEVELOPMENT WITH DEVTOOLS
    {
        "key": "ctrl+shift+l",
        "command": "r.loadAll"
    },
    {
        "key": "ctrl+shift+e",
        "command": "r.check"
    },
    {
        "key": "ctrl+shift+d",
        "command": "r.document"
    },
    {
        "key": "ctrl+shift+t",
        "command": "r.test"
    }
]