Skip to content
| Marketplace
Sign in
Visual Studio Code>Formatters>{styler}: Non-Invasive Pretty Printing of R CodeNew to Visual Studio Code? Get it now.
{styler}: Non-Invasive Pretty Printing of R Code

{styler}: Non-Invasive Pretty Printing of R Code

lorenzwalthert

| (0) | Free
Format R code using the {styler} R package
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

{styler} for Positron

This is experimental, written mostly by AI (Kiro), and long-term support is not guaranteed, breaking API changes can occur.

A Code OSS extension that formats R code using the {styler} package, primarily targetting Positron, since other Code OSS derivatives are compatible vscode-r extension that provides this functionality (and Positron is not). It registers a document formatting provider for R, so "Format Document" and "Format on Save" work automatically for .r, .R, .qmd, and .Rmd files. This extension is primarily aimed at people who use {styler} in pre-commit hooks / CI / command line and don't want to use Air for "format on Save", since the two formatters have some differences in how they format code and what features are supported.

Requirements

  • R ≥ 4.0 installed and Rscript available on your PATH (or configured via styler.rscriptPath)
  • styler ≥ 1.9.0 installed in your global R environment:
    install.packages("styler")
    

Installation

Search for "{styler}: Non-Invasive Pretty Printing of R Code" in the Extensions panel is the easiest way to install it. Alternatively, download it from Open VSX.

Once installed, the extension activates automatically when you open an R file. Trigger formatting with:

  • Format Document: Shift+Alt+F (Windows/Linux) or Shift+Option+F (macOS)
  • Format on Save: enable "editor.formatOnSave": true in your VS Code settings

Positron Compatibility

This extension is fully compatible with Positron.

Positron activates posit.air-vscode by default, which also registers an R formatter. When multiple formatters are active, VS Code and Positron will prompt you to choose the default formatter upon styling. To always use {styler}, add this to your settings.json:

{
  "[r]": {
    "editor.defaultFormatter": "lorenzwalthert.styler"
  }
}

Troubleshooting

"Rscript not found" — R is not installed or not on your PATH. Install R from r-project.org or set styler.rscriptPath to the full path of your Rscript binary.

Windows: "spawn EINVAL" or "Rscript not found" even though Rscript works in the terminal — The default R Windows installer adds Rscript.bat (a thin batch-file wrapper) to C:\Program Files\R\bin\ and puts that directory on the PATH. The extension handles .bat files automatically, so this should work out of the box. If you still see the error, set styler.rscriptPath explicitly to the versioned .exe, for example:

{ "styler.rscriptPath": "C:\\Program Files\\R\\R-4.4.3\\bin\\Rscript.exe" }

"Package 'styler' is not installed" — Run install.packages("styler") in R, then try formatting again.

"Formatting timed out" — The formatter took longer than styler.timeoutMs. Increase the timeout in settings.

Formatting failed with a syntax error — {styler} may not be able to format files with R syntax errors. Fix the error first, then format.

Configuration

All settings live under the styler namespace in VS Code settings.

Setting Type Default Description
styler.rscriptPath string "Rscript" Path to the Rscript binary. Defaults to "Rscript", resolved via PATH. Set to an absolute path if R is not on your PATH (e.g. "/usr/local/bin/Rscript").
styler.timeoutMs number 30000 Subprocess timeout in milliseconds. Clamped to the range [1000, 300000]. Increase this for very large files or slow machines.
styler.cache_root string "styler-perm" Value for the R option styler.cache_root. Controls where {styler} stores its formatting cache. See styler caching docs for details.

Example settings.json:

{
  "styler.rscriptPath": "/usr/local/bin/Rscript",
  "styler.timeoutMs": 60000,
  "styler.cache_root": "styler-perm"
}
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft