R Coding Practices
Application skill for R style learning (from the archived awesome-guidelines style capsules). Default to tidyverse + styler/lintr; when project declares Google R guide, apply BigCamelCase functions, explicit return(), and pkg::fun() qualification.
Core Principle
R analysis quality is consistent formatting + pipe-clear data flow, <- and snake_case objects, native |>, documented exports, mechanical styler/lintr gates.
When to Use / NOT
- R scripts, R packages, Quarto/Rmd analysis repos, Shiny apps.
- Setting up styler, lintr, testthat, R CMD check in CI.
NOT when:
- Renviron/secrets, never commit credentials.
- Generated
.Rd/NAMESPACE-only churn, validate hand-edited .R.
Workflow
- Syntax, spacing, braces,
<- (r-style-formatting-syntax.md).
- Naming/files, snake_case vs BigCamelCase policy (
r-style-naming-files.md).
- Functions/pipes,
|>, returns, control (r-style-functions-pipes.md).
- Docs/verify, roxygen, styler, lintr (
r-style-docs-verify.md).
- Verify, styler, lintr, tests on changed files.
Red Flags
= assignment
T/F instead of TRUE/FALSE
- Tabs or inconsistent indent vs 2-space styler profile
- Misaligned closing brace
- Dots in function names (non-S3)
- Mixed tidyverse snake and Google Camel function names
%>% in new code without magrittr feature need
- Right-hand pipe
-> (Google forbid)
- Implicit return in Google-baseline functions
- Missing explicit
return() in Google-baseline functions
- Unqualified external functions in Google codebase
- Blanket
@import package (Google)
attach()
- Semicolons or multiple statements per line
- Single-line braced
if/else bodies (except expression form)
if (length(x)) without explicit comparison
&/| inside scalar if
- Same-line
if (x) return(x)
- Partial argument matching
- Assignment inside function call
- Overlong unbroken pipes/calls
~ lambdas instead of \() for new short anonymous functions
- Spaces inside
{{ embracing }}
- Shadowing
c, mean, data
final/final2 filenames
- Libraries scattered mid-file
- Undocumented
@export
- Missing
pkg:: qualification (Google)
- No styler/lintr in CI for team projects
Verification
styler::style_file() or style_pkg() on changed paths
lintr::lint() with project .lintr config
devtools::test() / R CMD check for packages
- Roxygen coverage on new exports
- Capsule checklist on declared baseline (tidyverse vs Google)
References
awesome-guidelines/references/r-style-learning-note.md
awesome-guidelines/references/r-style-formatting-syntax.md
awesome-guidelines/references/r-style-naming-files.md
awesome-guidelines/references/r-style-functions-pipes.md
awesome-guidelines/references/r-style-docs-verify.md
1---2name: r-coding-practices3description: Use when authoring or reviewing R, tidyverse snake_case/<-/2-space layout, native |> pipes, roxygen2 docs, Google BigCamelCase/return/:: deltas when declared, and styler/lintr/testthat in CI.4---56# R Coding Practices78Application skill for R style learning (from the archived `awesome-guidelines` style capsules). Default to tidyverse + styler/lintr; when project declares Google R guide, apply BigCamelCase functions, explicit `return()`, and `pkg::fun()` qualification.910## Core Principle1112R analysis quality is **consistent formatting + pipe-clear data flow**, `<-` and snake_case objects, native `|>`, documented exports, mechanical styler/lintr gates.1314## When to Use / NOT1516- R scripts, R packages, Quarto/Rmd analysis repos, Shiny apps.17- Setting up styler, lintr, testthat, R CMD check in CI.1819**NOT when:**2021- Renviron/secrets, never commit credentials.22- Generated `.Rd`/NAMESPACE-only churn, validate hand-edited `.R`.2324## Workflow25261. **Syntax**, spacing, braces, `<-` (`r-style-formatting-syntax.md`).272. **Naming/files**, snake_case vs BigCamelCase policy (`r-style-naming-files.md`).283. **Functions/pipes**, `|>`, returns, control (`r-style-functions-pipes.md`).294. **Docs/verify**, roxygen, styler, lintr (`r-style-docs-verify.md`).305. **Verify**, styler, lintr, tests on changed files.3132## Red Flags3334- `=` assignment35- `T`/`F` instead of TRUE/FALSE36- Tabs or inconsistent indent vs 2-space styler profile37- Misaligned closing brace38- Dots in function names (non-S3)39- Mixed tidyverse snake and Google Camel function names40- `%>%` in new code without magrittr feature need41- Right-hand pipe `->` (Google forbid)42- Implicit return in Google-baseline functions43- Missing explicit `return()` in Google-baseline functions44- Unqualified external functions in Google codebase45- Blanket `@import` package (Google)46- `attach()`47- Semicolons or multiple statements per line48- Single-line braced `if`/`else` bodies (except expression form)49- `if (length(x))` without explicit comparison50- `&`/`|` inside scalar `if`51- Same-line `if (x) return(x)`52- Partial argument matching53- Assignment inside function call54- Overlong unbroken pipes/calls55- `~` lambdas instead of `\()` for new short anonymous functions56- Spaces inside `{{ embracing }}`57- Shadowing `c`, `mean`, `data`58- `final`/`final2` filenames59- Libraries scattered mid-file60- Undocumented `@export`61- Missing `pkg::` qualification (Google)62- No styler/lintr in CI for team projects6364## Verification6566- `styler::style_file()` or `style_pkg()` on changed paths67- `lintr::lint()` with project `.lintr` config68- `devtools::test()` / `R CMD check` for packages69- Roxygen coverage on new exports70- Capsule checklist on declared baseline (tidyverse vs Google)717273## References7475- `awesome-guidelines/references/r-style-learning-note.md`76- `awesome-guidelines/references/r-style-formatting-syntax.md`77- `awesome-guidelines/references/r-style-naming-files.md`78- `awesome-guidelines/references/r-style-functions-pipes.md`79- `awesome-guidelines/references/r-style-docs-verify.md`