- Use the standard package layout: `R/` for functions, `tests/testthat/` for tests, `man/` for documentation, `DESCRIPTION` and `NAMESPACE` at root.
- Use `roxygen2` with `#' @export` to manage `NAMESPACE` — never edit `NAMESPACE` manually.
- Prefer S3 generics (`UseMethod("my_generic")`) for simple dispatch and `R6` classes for stateful objects with reference semantics.
- Declare all package imports in `DESCRIPTION` under `Imports:` and use `::` (e.g., `dplyr::filter()`) instead of `library()` calls inside package functions.
- Use `usethis::use_package("pkg")` to add dependencies to `DESCRIPTION` — it ensures the dependency is properly recorded.
- Keep `Depends:` in `DESCRIPTION` only for packages whose namespace must be attached (rare) — prefer `Imports:` to avoid namespace pollution.
- Use `rlang::.data` pronoun in `dplyr` calls inside package functions to avoid `R CMD check` NOTEs about undefined variables.