R Code Formatter
Format and pretty-print R source — consistent operator spacing, bracket-depth indentation, optional = → <- assignment conversion, and blank-line normalization, approximating styler/tidyverse conventions. Includes basic syntax validation and a long-line report. Runs entirely in your browser.
Input
Output
| Issue |
|---|
| No data yet |
Guides
Paste inconsistently spaced R source and get back a cleanly formatted script — consistent spacing around binary operators, <- assignment, %>%/native |> pipes, and bracket-depth indentation, approximating styler/tidyverse conventions. An optional pass converts top-level = assignment to <-. A quick validation pass flags unbalanced brackets and unterminated strings. Everything runs locally in your browser.
How to use it
- Paste your R source code.
- Choose 2 spaces (tidyverse's default) or 4 spaces for indentation.
- Set the max line length used to flag overly long lines (80 is tidyverse's default).
- Toggle convert top-level
=to<-to normalize named-argument-safe assignment to the tidyverse-preferred arrow — it only rewrites assignments outside of function-call parentheses/brackets, where=is left alone as named-argument binding. - Check the Validation panel for syntax issues, then copy or download the formatted result.
What it formats
- Function definitions, default arguments, and control flow (
if/else,for,while,repeat). %>%/native|>pipe chains, spaced consistently on both sides.- Tight, unspaced accessors:
$,@,::/:::, and vector/list subsetting with[/[[. - Vectors, list literals, and named-argument calls.
- Line comments (
#), string literals (including R's raw strings,r"(...)"), and backtick-quoted identifiers (`my var`).
Does this fully replicate styler or the tidyverse style guide?
No — this is a lightweight, dependency-free tokenizer and bracket-depth indenter, not a full AST-based reformatter. It reindents by tracking bracket nesting rather than reflowing pipe chains or wrapping long function calls, so continuation lines in a pipe chain keep the indentation of their enclosing block rather than gaining an extra level. For a byte-for-byte match to styler::style_text(), run the real R package.
Is my source code uploaded anywhere?
No. Tokenizing and formatting run entirely in your browser; nothing is sent to a server.
Need to format a different language?
Check out the Haskell Code Formatter for Haskell source, or the Python Code Formatter if it's Python you're working with.
Use it from code
From 3 credits per callREST API
curl -X POST https://api.iotools.cloud/v1/tool/r-code-formatter \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"rInput": "library(dplyr)\nlibrary(ggplot2)\n\n# Summarise pen…",
"indentSize": "2",
"maxLineLength": "80",
"preferArrow": "true"
}'Swap in your own key from your account. The tool's fields are the body — no wrapper.
Ask an AI agent
Use the IOTools `r-code-formatter` tool (R Code Formatter) on this input:
YOUR_INPUT_HEREPaste this at any agent connected to the IOTools MCP server, then add your input.