R Code Formatter (Styler / Tidyverse Style)
Гид
Format R Code to the Tidyverse Style Instantly
The R Code Formatter applies tidyverse and styler conventions to any R script in your browser. Paste your code and the tool fixes spacing around <- assignment arrows, comparison operators, pipe operators like %>% и |>, indents nested blocks, and flags any line that exceeds your chosen length. Everything runs locally on your device, so your code never leaves the page.
Как использовать
- Paste your R source code into the input area, or upload a
.Rfile using the file picker. - Pick an indent width (2 spaces is the tidyverse default; 4 spaces is also supported).
- Set a maximum line length so the tool can flag any line that overruns the limit.
- Toggle whether top-level
=assignments should be rewritten to<-(named arguments inside function calls are always left alone). - Copy the formatted output or download it as an
.Rфайл.
Возможности
- Tidyverse spacing – Inserts a single space on both sides of binary operators, comparison operators, and pipes; keeps
$,::и@tight. - Configurable indent width – Choose 2 or 4 spaces for nested blocks, function bodies, and multi-line argument lists.
- Long-line detection – Flags every line that exceeds the configured maximum (defaults to 80 characters).
- Assignment normalisation – Optionally rewrites top-level
=assignments to<-without touching named arguments inside function calls. - Syntax sanity check – Detects unbalanced parentheses, brackets and braces, and unterminated strings.
- Comment and string safety – The tokenizer protects comment text, regular strings, raw strings (
r"(...)") and backtick-quoted identifiers from being reformatted.
Распространенные случаи использования
- Cleaning up R scripts inherited from collaborators or generated by older tools.
- Preparing data analysis or Shiny app code for code review.
- Normalising tutorial or blog post code snippets before publishing.
- Spot-checking generated R chunks inside Quarto, R Markdown or Jupyter notebooks.
- Quickly auditing a script for over-long lines before merging.
Часто задаваемые вопросы
-
What is the tidyverse style guide?
The tidyverse style guide is a community-maintained set of R coding conventions originally derived from Google's R style and refined by Hadley Wickham. It prescribes naming, spacing, line length, assignment operator choice and other formatting rules so that R code written by different authors looks and reads consistently.
-
Why does tidyverse prefer the assignment arrow <- over =?
R supports both <- and = for assignment, but they behave subtly differently in some contexts. = is also used to bind named function arguments, so reading code can be ambiguous about whether an identifier is being defined or passed as a parameter. The <- arrow has a single meaning, which makes intent clearer and matches the parsing rules R has used since its inception.
-
What is the difference between %>% and |>?
%>% is the magrittr pipe, originally provided by the magrittr package and popularised by dplyr. |> is the native R pipe added in R 4.1. They look similar but %>% is a function call that supports placeholder syntax like . and assignment pipe %%, while |> is a lightweight parser-level rewrite that is faster and has no external dependencies. Both pipes get a space on each side under tidyverse rules.
-
Why is 80 characters the conventional maximum line length?
The 80-column convention dates back to punch cards and early terminals, but it survives because it keeps code readable in side-by-side diffs, on smaller laptop screens, and in printed materials. Many projects relax this to 100 or 120 characters today, but tidyverse and styler default to 80 to preserve compatibility with the broadest range of editors and review tooling.
Установите наши расширения
Добавьте инструменты ввода-вывода в свой любимый браузер для мгновенного доступа и более быстрого поиска
恵 Табло результатов прибыло!
Табло результатов — это интересный способ следить за вашими играми, все данные хранятся в вашем браузере. Скоро появятся новые функции!
Подписаться на новости
все Новые поступления
всеОбновлять: Наш последний инструмент was added on Июн 4, 2026
