R Formatter is a VS Code extension that formats R source files using the styler package. It integrates with VS Code's built-in format-on-save and Format Document commands.
Features
Format .R, .r, .Rmd, and .rmd files using styler::style_file().
Checks for R and styler on startup and offers to install styler if missing.
Configurable formatting scope: spaces, indentation, line breaks, or full token-level changes.
Configurable indentation width, line length, strict mode, roxygen example formatting, and comment spacing.
Works with VS Code's Format Document, Format on Save, and format-on-type features.
Supports a custom Rscript path for non-standard R installations.
Requirements
R must be installed and Rscript must be on PATH (or configured via the r-formatter.rscriptPath setting).
The styler R package must be installed. If it is missing, the extension will prompt you to install it automatically on startup.
To install styler manually, run in R:
install.packages("styler")
Settings
Setting
Default
Description
r-formatter.rscriptPath
"Rscript"
Path to the Rscript executable.
r-formatter.scope
"tokens"
How invasive the formatter is: none, spaces, indention, line_breaks, or tokens.
r-formatter.strict
true
Forces exactly one space or line break where required.
r-formatter.indentBy
2
Number of spaces per indentation level.
r-formatter.lineLength
80
Target line length (sets R's width option before formatting).