copilot review updates

This commit is contained in:
Mike-Hanna 2025-10-23 13:15:44 -04:00
parent a7098f61da
commit 7ca6f6bd4c

View File

@ -1,6 +1,6 @@
--- ---
description: "R language and document formats (R, Rmd, Quarto): coding standards and Copilot guidance for idiomatic, safe, and consistent code generation." description: 'R language and document formats (R, Rmd, Quarto): coding standards and Copilot guidance for idiomatic, safe, and consistent code generation.'
applyTo: "**/*.{R,r,Rmd,rmd,qmd}" applyTo: '**/*.{R,r,Rmd,rmd,qmd}'
--- ---
# R Programming Language Instructions # R Programming Language Instructions
@ -13,8 +13,7 @@ Help GitHub Copilot generate idiomatic, safe, and maintainable R code across pro
- **Match the projects style.** If the file shows a preference (tidyverse vs. base R, `%>%` vs. `|>`), follow it. - **Match the projects 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. - **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()`. - **Qualify non-base functions in examples/snippets**, e.g., `dplyr::mutate()`, `stringr::str_detect()`. In project code, using `library()` is acceptable when thats the repo norm.
In project code, using `library()` is acceptable when thats the repo norm.
- **Naming:** `lower_snake_case` for objects/files; avoid dots in names. - **Naming:** `lower_snake_case` for objects/files; avoid dots in names.
- **Side effects:** Never call `setwd()`; prefer project-relative paths (e.g., `here::here()`). - **Side effects:** Never call `setwd()`; prefer project-relative paths (e.g., `here::here()`).
- **Reproducibility:** Set seeds locally around stochastic operations using `withr::with_seed()`. - **Reproducibility:** Set seeds locally around stochastic operations using `withr::with_seed()`.
@ -87,8 +86,7 @@ In project code, using `library()` is acceptable when thats the repo norm.
## Copilot-Specific Guidance ## Copilot-Specific Guidance
- If the current file uses tidyverse, **suggest tidyverse-first patterns** (e.g., `dplyr::across()` instead of superseded verbs). - If the current file uses tidyverse, **suggest tidyverse-first patterns** (e.g., `dplyr::across()` instead of superseded verbs). If base-R style is present, **use base idioms**.
If base-R style is present, **use base idioms**.
- Qualify non-base calls in suggestions (e.g., `dplyr::mutate()`). - Qualify non-base calls in suggestions (e.g., `dplyr::mutate()`).
- Suggest vectorized or tidy solutions over loops when idiomatic. - Suggest vectorized or tidy solutions over loops when idiomatic.
- Prefer small helper functions over long pipelines. - Prefer small helper functions over long pipelines.
@ -106,7 +104,7 @@ scores$z <- vapply(scores$x, safe_log, numeric(1))
# Tidyverse variant (if this file uses tidyverse) # Tidyverse variant (if this file uses tidyverse)
result <- tibble::tibble(id = 1:5, x = c(1, 3, 2, 5, 4)) |> result <- tibble::tibble(id = 1:5, x = c(1, 3, 2, 5, 4)) |>
dplyr::mutate(z = purrr::possibly(log, otherwise = NA_real_)(x)) |> dplyr::mutate(z = purrr::map_dbl(x, purrr::possibly(log, otherwise = NA_real_))) |>
dplyr::filter(z > 0) dplyr::filter(z > 0)
# Example reusable helper with roxygen2 doc # Example reusable helper with roxygen2 doc