Project-level instructions for AI coding agents working on this repository. GitHub Copilot Code Review, Copilot coding agent, Codex, and other AGENTS.md-aware tools read this file directly.
Package overview
statsExpressions is an R package that creates tidy data frames and plotmath expressions with details from statistical tests. It serves as the statistical backend for ggstatsplot.
Architecture
Main functions (R/)
- Statistical tests:
oneway_anova(),two_sample_test(),one_sample_test(),corr_test(),contingency_table(),meta_analysis(),pairwise_comparisons(), andpairwise_contingency_table(). - Supporting public helpers include
centrality_description(),add_expression_col(),tidy_model_expressions(),tidy_model_parameters(),extract_stats_type(),stats_type_switch(),long_to_wide_converter(), andcomplete_subjects(). - The package standardizes parametric, nonparametric, robust, and Bayesian
typelabels, but supported choices vary by function. Do not assume every exported function has this interface; for example,pairwise_contingency_table()does not accepttype. - Statistical functions return tibbles with a special
expressioncolumn for plotmath output where applicable.
Key internal helpers
-
tidy_model_effectsize(): Convert effect-size output to tidy conventions. -
extract_estimate_type()andextract_statistic_text(): Choose plotmath labels for estimates and test statistics. -
prior_switch(): Choose prior labels for Bayesian output.
Dependencies
Core dependencies include the tidyverse stack (dplyr, purrr, tidyr, and rlang) and the easystats ecosystem (insight, parameters, performance, effectsize, bayestestR, datawizard, and correlation). Treat DESCRIPTION as the source of truth for dependency constraints and the minimum supported R version.
Developer workflow
Use the repository Makefile for routine package tasks:
make install_deps # Install dependencies declared in DESCRIPTION
make build # Build the package tarball
make check # Build and run R CMD check --no-manual
make install # Build and install the package locally
make document # Regenerate roxygen docs and render README.Rmd
make lint # Run lintr::lint_package()
make format # Run air format .
make hooks # Run all prek hooks
make clean # Remove package build and check artifacts
make update_deps # Refresh dependency constraints (maintenance only)Validation
Start with the narrowest check that proves a change, such as the affected testthat files and snapshots. When a change affects shared behavior, dependencies, generated metadata, or workflows, also run the full validation gate:
Versioning and changelog
- Development versions use a fourth-component
.9000suffix. - Keep the version in
DESCRIPTION,codemeta.json, and the firstNEWS.mdheading synchronized. - Keep
NEWS.mdconcise and user-facing. Record behavior and compatibility changes, such as a higher minimum R version, a newly required package, or a dependency minimum version that new code requires; omit routine dependency updates and lint, formatting, CI, or generated-file maintenance.
Testing
- The package uses
testthatedition 3 with parallel execution. - Snapshot tests are used extensively for both tidy statistical output and the
expressioncolumn. - Tests cover source areas, but helper and shared source files may be exercised by broader test files rather than a one-to-one filename match.
- Set seeds before Bayesian or otherwise stochastic tests, and only there.
- Use
skip_if_not_installed()for optional dependencies. - Suppress warnings only when a test intentionally exercises a warning-producing path.
- Codecov requires 100% project and patch coverage.
- Use
patrick::with_parameters_test_that()to cover combinations of inputs, with a.test_namecolumn in.cases(thetest_namecolumn is deprecated). Snapshot each case’s output rather than hand-writing expected expressions.
Follow the existing snapshot style:
test_that("descriptive name", {
df <- function_under_test(data = dataset, x = var1, y = var2)
expect_snapshot(dplyr::select(df, -expression))
expect_snapshot(df[["expression"]])
})Code conventions
- Use
lintrfor linting and Air for formatting; CI runsair format . --check. - Use snake_case for functions and variables.
- Use the base R pipe (
|>), not the magrittr pipe (%>%). - Preserve tidy evaluation for unquoted column arguments.
- Inside
mutate()and other data-masking calls, includingglue()called there, a bare name resolves to a column ofdatabefore a local variable. Build local values such as expression templates before the call and refer to them with.env$name, so input columns can’t shadow them.
Roxygen documentation
- Roxygen uses Markdown and the
pkgapiandroxyglobalsroclets configured inDESCRIPTION. - Use
@autoglobalfromroxyglobalswhere appropriate. - Shared documentation tables and prose live in
man/rmd-fragments/; shared example code lives inman/examples/. - Keep the README introductory and link to articles for detailed method tables and output schemas. Reuse canonical fragments and example files rather than maintaining copies in multiple documentation sources.
- Add examples only when they explain a distinct workflow or important behavior. Prefer concise prose and cross-references for routine details; avoid expanding website builds and CRAN checks with examples for every function or option.
- Use sentence case for prose headings, preserving function names, proper nouns, and published titles. Keep table labels such as Hypothesis testing and Effect size estimation bold.
- End each vignette with a Citation section calling
citation("statsExpressions"); the package metadata is the source of truth. Avoid relative child documents for this executable footer: pkgdown can render it from a temporary Markdown file. -
@examplesIfcannot wrap an@examplefile. To keep aNOT_CRANguard around a shared example file, use the explicit\dontshow{if (...) withAutoprint(\{ # examplesIf}and\dontshow{\}) # examplesIf}@exampleslines around@example, as inR/two-sample-test.R. The wrapper preserves automatic printing inside the conditional block, including on R >= 4.5; it is not a compatibility fallback. The# examplesIfmarkers let pkgdown recognise the conditional examples. - After changing roxygen comments, run
make documentand commit the generatedNAMESPACEorman/*.Rdchanges. Do not edit generated.Rdfiles by hand.
Common function parameters
-
data: Input data frame. -
x,y: Unquoted column names using tidy evaluation. -
type: Usually one of"parametric","nonparametric","robust", or"bayes"where supported. -
paired: Whether the design is paired or within-subjects. -
digits: Number of decimal places. -
conf.level: Confidence level between 0 and 1.
Important patterns
Statistical method selection
Functions normalize supported type values with extract_stats_type() and then select the appropriate statistical and effect-size functions. Follow the existing per-function branching and argument construction; do not assume one shared switch() shape applies to every analysis.
Expression generation
Statistical results are standardized and passed to add_expression_col() or the specialized expression helpers. Keep returned columns and attributes stable because ggstatsplot consumes them.
Easystats integration
Use tidy_model_parameters() and tidy_model_effectsize() to normalize easystats output rather than duplicating column-renaming and confidence-interval logic.
Files to update together
When modifying a function, consider all relevant surfaces:
-
R/<function>.Ror its helper file. - The corresponding files under
tests/testthat/. - Generated
man/<function>.Rdafter roxygen regeneration. -
man/rmd-fragments/<function>.Rmdwhen that fragment exists. Fragments are shared by the Rd files,README.Rmd, and the vignettes, so edit the fragment rather than its rendered copies. -
man/examples/examples-<function>.Rwhen that example file exists. These files are shared by the Rd files and the Data frame outputs article. -
README.Rmd(then re-renderREADME.md) and the vignettes undervignettes/when user-facing behavior or output changes. -
NEWS.mdfor user-facing changes.
Repository skills
Task-specific instructions live in .agents/skills/. Read a skill only when the task matches it:
-
create-release: prepare, submit, resume, or publish a CRAN release. -
update-dependencies: update dependencies to their latest versions, change the minimum R version, or add, remove, or move a dependency. -
maintain-ci: change or debug workflows under.github/workflows/.
User-invoked prompts for other tasks live in .github/prompts/. Keep each topic in exactly one place: AGENTS.md for every-session rules, a skill or a prompt for task-specific procedures.
