Table of Contents generated with DocToc
- Contributing to wehoop
- Development Setup
- Workflow
- Naming Conventions
- Documentation Maintenance
- Commit Messages
- Pull Requests
- Testing
- CI / GitHub Actions
- Reporting Issues
- License
Thank you for your interest in contributing to wehoop! This guide will help you get started.
Development Setup
- Fork and clone the repository
-
Install dependencies: Open the project in RStudio and run
devtools::install_deps(dependencies = TRUE) -
Create a feature branch from
main:git checkout -b feat/your-feature main
Workflow
Making Changes
- Edit source code in
R/ - Regenerate docs:
devtools::document() - Run tests:
devtools::test() - Check the package:
devtools::check()
Adding a New WNBA Stats API Endpoint
-
Create the function in the appropriate
R/wnba_stats_*.Rfile following the existing pattern:- Use
wnba_endpoint()+request_with_proxy()for HTTP - Parse response with
purrr::pluck()->data.frame()->janitor::clean_names()->make_wehoop_data() - Use
%||%(rlang) for null safety on every extracted field
- Use
-
Add roxygen docs with
@export,@family,@return(including column markdown tables), and@detailsexample -
Create a test in
tests/testthat/withskip_on_cran()andskip_on_ci()guards - Update NEWS.md with a description of the new function
- Run
devtools::document()to update NAMESPACE
Naming Conventions
Function Names
| Data Source | Prefix | Example |
|---|---|---|
| WNBA Stats API | wnba_ |
wnba_leagueleaders(), wnba_boxscoretraditionalv3()
|
| ESPN WNBA | espn_wnba_ |
espn_wnba_pbp(), espn_wnba_teams()
|
| ESPN WBB | espn_wbb_ |
espn_wbb_pbp(), espn_wbb_teams()
|
| NCAA WBB | ncaa_wbb_ |
ncaa_wbb_teams() |
| Fox Sports |
fox_wnba_ / fox_wbb_
|
fox_wnba_pbp(), fox_wbb_teams()
|
| Basketball-Reference | bref_wnba_ |
bref_wnba_player_stats() |
| Her Hoop Stats | hhs_ |
hhs_teams() (subscription) |
| Bart Torvik | bart_wbb_ |
bart_wbb_ratings() |
| International |
fiba_, genius_, atrium_, nbl_, scb_, feb_, tbf_, wjbl_ (+ per-competition aliases) |
fiba_gdap_schedule(), genius_pbp(), wjbl_pbp()
|
| Data loaders |
load_wnba_ / load_wbb_
|
load_wnba_pbp(), load_wbb_team_box()
|
| NCAA WBB loaders | load_ncaa_wbb_ |
load_ncaa_wbb_pbp(), load_ncaa_wbb_rapm()
|
General Naming Rules
- snake_case for all function names, variables, and parameters
-
Internal helpers (not exported) are prefixed with
.(e.g.,.players_on_court_v3_wnba()) -
Parameter names use
snake_casein R, mapped toPascalCasefor the WNBA Stats API (e.g.,game_id->GameID) -
Game IDs must always be passed through
pad_id()before API calls (zero-pads to 10 digits) -
File names follow the pattern
R/wnba_stats_*.R,R/espn_*.R,R/ncaa_wbb_*.R
V2 vs V3 API Patterns
-
V2 endpoints (e.g.,
boxscoretraditionalv2): ReturnresultSets[].headers[] + rowSet[][]. Parsed viawnba_stats_map_result_sets(). -
V3 endpoints (e.g.,
boxscoretraditionalv3): Return nested JSON. Parsed viapurrr::pluck()->data.frame()-> pipeline.
Data Processing Pipeline
All returned data frames must pass through:
raw_data %>%
data.frame(stringsAsFactors = FALSE) %>%
dplyr::as_tibble() %>%
janitor::clean_names() %>%
make_wehoop_data("Description from WNBA.com", Sys.time())Roxygen Documentation
Every exported function needs:
-
@nameand@rdnametags withNULLobject preceding the function -
@titlewith bold markdown description -
@authortag -
@paramfor every parameter (including...) -
@returnwith markdown tables documenting column names and types -
@importFromfor specific function imports @export-
@familyfor grouping in pkgdown (e.g.,"WNBA PBP Functions","WNBA Boxscore V3 Functions") -
@detailswith a runnable example code block
Code Style
- Follow tidyverse style:
snake_case, 2-space indentation - Internal helpers start with
.(e.g.,.players_on_court_v3_wnba()) - Game IDs must be passed through
pad_id()before API calls - Use
%||%(rlang) for null-safe defaults when parsing API responses - Initialize the return variable before
tryCatch, wrap the body asexpr = .wehoop_with_warnings("<function name>", { ... }), and give thetryCatchnowarning =handler. Awarning =handler stops the body at the first warning and returns the empty fallback;.wehoop_with_warnings()re-raises each warning as awehoop_warningnaming the function and lets the body finish. - Every
error =handler must reportconditionMessage(e)(directly or through.report_api_error()), so a timeout, a connection reset or a parse failure is reported with its cause.tests/testthat/test-handler_causes.Rfails a block or.report_api_error()handler that drops it when the function’s first request fails. It does not select value fallbacks such aserror = function(e) NULL, nor the functions in its skip list; give those a focused test.
Documentation Maintenance
Two regeneration steps are part of the commit workflow whenever the relevant sources change. Both are mechanical — never edit the generated regions by hand.
Markdown TOCs (doctoc)
NEWS.md, CLAUDE.md, CONTRIBUTING.md, .github/copilot-instructions.md, and .github/pull_request_template.md carry a doctoc-generated table of contents inside the standard marker comments. After editing any of those files, regenerate the TOC before committing:
Rscript tools/run_doctoc.R --maxlevel 2 \
NEWS.md CLAUDE.md CONTRIBUTING.md \
.github/copilot-instructions.md .github/pull_request_template.mdcran-comments.md is intentionally excluded — it is a short release-notes file submitted to CRAN and does not need a TOC.
tools/run_doctoc.R is a no-deps R replacement for the npm doctoc CLI — it produces output indistinguishable from the upstream tool, is idempotent (a no-op if no headings changed), and runs without Node.js. Use --maxlevel 2 so the TOC only lists # and ## headings; level-3 sub-entries crowd the nav.
README.md (rmarkdown)
README.md is rendered from README.Rmd. The Rmd carries output: github_document: { toc: true, toc_depth: 2 }, so the README has its own auto-generated TOC. After editing README.Rmd, re-render before committing:
devtools::build_readme()Commit README.Rmd and the regenerated README.md together. Never hand-edit README.md.
DESCRIPTION (usethis)
After editing DESCRIPTION (adding/removing packages, bumping versions, updating Authors@R, etc.), normalize formatting before committing:
usethis::use_tidy_description()This re-orders fields, alphabetizes Imports/Suggests, and reflows long lines so subsequent diffs stay minimal. Run it even for one-line edits.
Release notes triad: NEWS.md / cran-comments.md / _pkgdown.yml
Three files describe the same release at different audiences. Whenever you add a NEWS.md bullet, think through all three before committing:
NEWS.md— authoritative changelog for downstream users; rendered into the pkgdown changelog. All new bullets go under the most recent unreleased version heading (currently# **wehoop 3.1.0**; 3.0.0 shipped to CRAN on 2026-08-24, 3.1.0 is not yet submitted). Do NOT create a new version section ahead of release. Add to or extend an existing subsection (### Bug fixes,### Deprecations,### Test infrastructure, etc.) instead of starting a new one when the change is incremental. When a version ships to CRAN, the next development version gets its own heading and the rule rolls forward.cran-comments.md— what gets submitted to CRAN. Every behavioral or user-visible change you add toNEWS.mdshould also be reflected incran-comments.mdbefore submission. The two files are not duplicates:NEWS.mdis the long-form changelog,cran-comments.mdis the short-form release summary. If aNEWS.mdbullet is purely internal (refactor, test infrastructure, dev tooling) it can be omitted fromcran-comments.md._pkgdown.yml— the pkgdown reference index. New exported functions need to land in the rightreference:section. The existing wehoop config usesstarts_with("wnba_")/starts_with("espn_")/starts_with("ncaa_")selectors so new functions matching those prefixes are picked up automatically; explicitly-listed functions need a manual entry. Functions deprecated vialifecycle::deprecate_stop()+@keywords internalare excluded from the rendered index by default — preview withpkgdown::build_site()when in doubt.
When the change touches the API surface (new export, deprecation, removal), include a one-line note in your commit message confirming you’ve checked all three files.
Commit Messages
Use Conventional Commits:
feat: add wnba_playbyplayv3() endpoint wrapper
fix: correct WNBA time calculations for 10-min quarters
docs: update roxygen for wnba_pbp() version param
test: add column validation for V3 boxscore endpoints
refactor: extract clock parsing into helper
chore: update .Rbuildignore
ci: update GitHub Actions workflow versions
Optional scope is encouraged for clarity (e.g., feat(pbp): ..., docs(instructions): ...). Use type!: or a BREAKING CHANGE: footer for breaking changes. Split unrelated work into separate commits for reviewability.
Important: Never include AI agents or assistants (e.g., Claude, Copilot) as co-authors on commits. Omit all Co-Authored-By trailers referencing AI tools.
Pull Requests
- Target the
mainbranch - Include a clear description of what changed and why
- Ensure
devtools::check()passes with no errors or warnings - Add tests for new functions
- Update NEWS.md for user-facing changes
Testing
Test Pattern
When writing tests for WNBA Stats API endpoints, follow this pattern:
test_that("WNBA Endpoint Name", {
skip_on_cran()
skip_on_ci()
x <- wnba_function(game_id = "1022200034")
cols_x1 <- c("col1", "col2", ...)
expect_in(sort(cols_x1), sort(colnames(x[[1]])))
expect_s3_class(x[[1]], "data.frame")
Sys.sleep(3) # Rate limiting
})For intermittent or empty responses:
Test environment variables
Live tests are off unless you set the variable for the source you are testing (helpers in tests/testthat/helper-skip.R and helper-intl.R):
| Variable | Enables | Helper |
|---|---|---|
WNBA_STATS_TESTS=1 |
WNBA Stats API tests | skip_wnba_stats_test() |
ESPN_TESTS=1 |
ESPN API tests | skip_espn_test() |
NCAA_WBB_TESTS=1 |
NCAA WBB tests | skip_ncaa_wbb_test() |
FOX_TESTS=1 |
Fox Sports tests | skip_fox_test() |
OFFICIAL_NBA_TESTS=1 |
official.nba.com tests | skip_official_nba_test() |
WEHOOP_LOAD_TESTS=1 |
load_*() release-asset tests (large downloads) |
skip_load_test() |
WEHOOP_INTL_LIVE_TESTS=1 |
international-family live tests | skip_intl_live() |
BREF_TESTS=1 |
Basketball-Reference tests | skip_bref_test() |
TORVIK_TESTS=1 |
Bart Torvik (T-Rank) tests | inline check in test-bart_wbb.R
|
GENIUS_PROXY |
a proxy URL; the Genius live tests also need it | skip_intl_live("GENIUS_PROXY") |
For example: Sys.setenv(ESPN_TESTS = "1"); devtools::test(filter = "espn_wnba_pbp").
Note: Every live test is skipped on CRAN and on CI whatever the toggles say (skip_live_test() in tests/testthat/helper-skip.R, and skip_intl_live() in helper-intl.R), and an unset or empty toggle means skip. Run them locally. If your ~/.Renviron sets any of these, unset them in the session (Sys.unsetenv()) for an offline run.
CI / GitHub Actions
The repository uses GitHub Actions for R CMD check (macOS and Ubuntu release on every push and PR; the weekly cron and manual runs add Windows release and a non-blocking Ubuntu R-devel job), test coverage, a URL check, and pkgdown site deployment. GITHUB_TOKEN is the only secret the workflows need. R-CMD-check passes the WNBA_STATS_TESTS, ESPN_TESTS and NCAA_WBB_TESTS repository variables through, but live tests skip on CI regardless (see above).
Reporting Issues
When filing a bug report, please include:
- A minimal reprex (reproducible example) using
reprex::reprex() - The game ID or parameters used
- Your
sessionInfo()output - The specific error message or unexpected output
Use the bug report template when opening a new issue.
License
By contributing, you agree that your contributions will be licensed under the MIT License.
