Home › R › R tidyverse Copilot path instructions
R tidyverse Copilot path instructions
Path-specific Copilot instructions for R analysis code: tidyverse style, renv, native pipe, reproducible Quarto reports, and testthat.
GitHub CopilotR
How to use
Save this as .github/instructions/r.instructions.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.
Note: Review and test before use. Provided as is, without warranty. See Terms.
.github/instructions/r.instructions.mdDownload ---
applyTo: "**/*.R,**/*.qmd,**/*.Rmd"
description: R and tidyverse conventions
---
# R (tidyverse)
- Dependencies are managed with `renv`: after adding a package run `renv::snapshot()` and commit `renv.lock`. Never call `install.packages()` inside scripts.
- Follow the tidyverse style guide: `snake_case`, `<-` for assignment, spaces around operators, lines under 80 chars. Format with `styler::style_file()`; lint with `lintr`.
- Use the native pipe `|>` in new code (R 4.1+), dplyr verbs (`filter`, `mutate`, `summarise(.by = )`), and tidyr for reshaping.
- Read data with `readr`/`arrow` and explicit `col_types`; write outputs to `output/` or `data/processed/`, never overwrite `data/raw/`.
- Paths with `here::here()`; no `setwd()` or absolute paths.
- No `library()` calls inside functions; use `pkg::fun()` there. Keep `library()` at the top of scripts.
- Functions over copy-paste: if code repeats three times, write a function with roxygen comments.
- Randomness: `set.seed()` once at the top of any script that samples or models.
- Plots with ggplot2: labelled axes with units, `theme_minimal()` or the project theme, colour-blind safe palettes (`viridis`).
- Reports in Quarto (`.qmd`) render from a clean session: `quarto render`.
- Packages: tests with `testthat` (`usethis::use_test()`), checks with `devtools::check()`.