MR
Mayur Rathi
@github
⭐ 34.1k GitHub stars

R

R是一款code方向的AI技能,核心价值是R language and document formats (R, Rmd, Quarto): coding standards and Copilot guidance for idiomatic, safe, and consistent code generation,可用于解决开发者在code领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。

R language and document formats (R, Rmd, Quarto): coding standards and Copilot guidance for idiomatic, safe, and consistent code generation.

Last verified on: 2026-05-30
mkdir -p ./skills/r && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/r/SKILL.md -o ./skills/r/SKILL.md

Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).

Skill Content

# R Programming Language Instructions


Purpose


Help GitHub Copilot generate idiomatic, safe, and maintainable R code across projects.


Core Conventions


- **Match the project’s style.** If the file shows a preference (tidyverse vs. base R, `%>%` vs. `|>`), follow it.

- **Prefer clear, vectorized code.** Keep functions small and avoid hidden side effects.

- **Qualify non-base functions in examples/snippets**, e.g., `dplyr::mutate()`, `stringr::str_detect()`. In project code, using `library()` is acceptable when that’s the repo norm.

- **Naming:** `lower_snake_case` for objects/files; avoid dots in names.

- **Side effects:** Never call `setwd()`; prefer project-relative paths (e.g., `here::here()`).

- **Reproducibility:** Set seeds locally around stochastic operations using `withr::with_seed()`.

- **Validation:** Validate and constrain user inputs; use typed checks and allowlists where possible.

- **Safety:** Avoid `eval(parse())`, unvalidated shell calls, and unparameterized SQL.


Pipe Operators


- **Native pipe `|>` (R ≥ 4.1.0):** Prefer in R ≥ 4.1 (no extra dependency).

- **Magrittr pipe `%>%`:** Continue using in projects already committed to magrittr or when you need features like `.`, `%T>%`, or `%$%`.

- **Be consistent:** Don't mix `|>` and `%>%` within the same script unless there's a clear technical reason.


Performance Considerations


- **Large datasets:** consider `data.table`; benchmark with your workload.

- **dplyr compatibility:** Use `dtplyr` to write dplyr syntax that translates to data.table operations automatically for performance gains.

- **Profiling:** Use `profvis::profvis()` to identify performance bottlenecks in your code. Profile before optimizing.

- **Caching:** Use `memoise::memoise()` to cache expensive function results. Particularly useful for repeated API calls or complex computations.

- **Vectorization:** Prefer vectorized operations over loops. Use `purrr::map_*()` family or `apply()` family for remaining iteration needs.


Tooling & Quality


- **Formatting:** `styler` (tidyverse style), two-space indents, ~100-char lines.

- **Linting:** `lintr` configured via `.lintr`.

- **Pre-commit:** consider `precommit` hooks to lint/format automatically.

- **Docs:** roxygen2 for exported functions (`@param`, `@return`, `@examples`).

- **Tests:** prefer small, pure, composable functions that are easy to unit test.

- **Dependencies:** manage with `renv`; snapshot after adding packages.

- **Paths:** prefer `fs` and `here` for portability.


Data Wrangling & I/O


- **Data frames:** prefer tibbles in tidyverse-heavy files; otherwise base `data.frame()` is fine.

- **Iteration:** use `purrr` in tidyverse code. In base-style code, prefer type-stable, vectorized patterns such as `vapply()`

(for atomic outputs) or `Map()` (for elementwise operations) instead of explicit `for` loops when they improve clarity or performance.

- **Strings & Dates:** use `stringr`/`lubridate` where already present; otherwise use clear base helpers (e.g., `nchar()`, `substr()`, `as.Date()` with explicit format).

- **I/O:** prefer explicit, typed readers (e.g., `readr::read_csv()`); make parsing assumptions explicit.


Plotting


- Prefer `ggplot2` for publication-quality plots. Keep layers readable and label axes and units.


Error Handling


- In tidyverse contexts, use `rlang::abort()` / `rlang::warn()` for structured conditions; in base-only code, use `stop()` / `warning()`.

- For recoverable operations:

- Use `purrr::possibly()` when you want a typed fallback value of the same type (simpler).

- Use `purrr::safely()` when you need to capture both results and errors for later inspection or logging.

- Use `tryCatch()` in base R for fine-grained control or compatibility with non-tidyverse code.

- Prefer consistent return structures—typed outputs for normal flows, structured lists only when error details are required.


Security Best Practices


- **Command execution:** Prefer `processx::run()` or `sys::exec_wait()` ov

🎯 Best For

  • Technical writers
  • API documentation teams
  • UI designers
  • Product designers
  • Claude users

💡 Use Cases

  • Generating JSDoc/TSDoc comments
  • Writing README files for new projects
  • Generating component mockups
  • Creating design system tokens

📖 How to Use This Skill

  1. 1

    Install the Skill

    Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.

  2. 2

    Load into Your AI Assistant

    Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.

  3. 3

    Apply R to Your Work

    Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.

  4. 4

    Review and Refine

    Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.

❓ Frequently Asked Questions

Does it follow my documentation style?

Most documentation skills respect existing style. Provide a style guide or example in your prompt.

Does this work with Figma?

Some design skills integrate with Figma plugins. Check the Works With section for supported tools.

Is R compatible with Cursor and VS Code?

Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.

Do I need specific dependencies for R?

Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.

How do I install R?

Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/r/SKILL.md, ready to use.

⚠️ Common Mistakes to Avoid

Auto-generating without reviewing

AI documentation can contain inaccuracies. Always verify technical accuracy.

Skipping usability testing

AI-generated designs should be validated with real users before development.

Skipping validation

Always test AI-generated code changes, even for simple refactors.

Missing dependency updates

Check if the skill requires updated dependencies or new packages.

🔗 Related Skills