不喜欢广告? 无广告 今天

R Code Formatter (Styler / Tidyverse Style)

开发人员文本
广告 移除?

或者
Used to flag overly long lines (tidyverse default is 80).
广告 移除?

指导

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.

如何使用

  1. Paste your R source code into the input area, or upload a .R file using the file picker.
  2. Pick an indent width (2 spaces is the tidyverse default; 4 spaces is also supported).
  3. Set a maximum line length so the tool can flag any line that overruns the limit.
  4. Toggle whether top-level = assignments should be rewritten to <- (named arguments inside function calls are always left alone).
  5. 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.

常问问题

  1. 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.

  2. 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.

  3. 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.

  4. 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.

想要享受无广告的体验吗? 立即无广告

安装我们的扩展

将 IO 工具添加到您最喜欢的浏览器,以便即时访问和更快地搜索

添加 Chrome 扩展程序 添加 边缘延伸 添加 Firefox 扩展 添加 Opera 扩展

记分板已到达!

记分板 是一种有趣的跟踪您游戏的方式,所有数据都存储在您的浏览器中。更多功能即将推出!

广告 移除?
广告 移除?
广告 移除?

新闻角 包含技术亮点

参与其中

帮助我们继续提供有价值的免费工具

给我买杯咖啡
广告 移除?