Skip to content

fix(statcast): recognize Savant's miss_distance column (#408) - #412

Merged
saiemgilani merged 1 commit into
BillPetti:masterfrom
cfarese:fix/statcast-miss-distance
Jul 23, 2026
Merged

fix(statcast): recognize Savant's miss_distance column (#408)#412
saiemgilani merged 1 commit into
BillPetti:masterfrom
cfarese:fix/statcast-miss-distance

Conversation

@cfarese

@cfarese cfarese commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Pull Request

Table of Contents generated with DocToc

Summary

statcast_search() now returns Baseball Savant's miss_distance column (the bat-tracking swing-and-miss distance) and stops silently mislabeling the columns that follow it.

Type of Change

  • feat -- New feature (new endpoint wrapper, new exported function)
  • fix -- Bug fix (non-breaking change that fixes an issue)
  • docs -- Documentation only (roxygen, README, vignettes, NEWS)
  • test -- Adding or updating tests
  • refactor -- Code change that neither fixes a bug nor adds a feature
  • chore -- Tooling, build, or maintenance change
  • perf -- Performance improvement

Related Issues

Closes #408

Background & Context

Source: Baseball Savant (statcast_search() / scrape_statcast_savant*()).

The earlier hardening (#337/#354/#371/#390) fixed the Can't assign 118 names to a 119-column data.table crash by assigning the canonical column names positionally and letting any extra columns pass through. That logic only self-heals when Savant appends a column at the end. Savant instead inserted miss_distance mid-frame at position 93, between swing_length and estimated_slg_using_speedangle. So the positional rename labeled column 93 (real miss_distance data) as estimated_slg_using_speedangle and shifted all 26 columns after it one position off: miss_distance never appeared, and the trailing bat-tracking columns were silently mislabeled (it even produced a duplicate intercept_ball_minus_batter_pos_y_inches, which process_statcast_payload() then dropped). That matches #408: "downloads without the error, but there's no miss_distance column."

Changes Made

File / Function Change
R/sc_statcast_search.R (statcast_search) Insert "miss_distance" into statcast_columns at position 93 (after swing_length); add @return row for it; add a comment explaining that mid-frame inserts must be placed in the canonical vector
man/statcast_search.Rd Regenerated @return table row via devtools::document() (roxygen2 7.3.3)
tests/testthat/test-statcast_search.R Add miss_distance to the expected-columns vector
NEWS.md Add bug-fix bullet under # baseballr 2.0.0### Bug fixes (#408)

Submission Checklist

  • Code follows tidyverse style and the conventions in CLAUDE.md.
  • I ran devtools::document() and committed the regenerated man/ and NAMESPACE (no hand edits).
  • Roxygen blocks are complete (@param, @return, @export, runnable @examples).
  • I added or updated tests, respecting the live-API gating.
  • devtools::check() passes with no new errors, warnings, or notes.
  • I updated NEWS.md; cran-comments.md/_pkgdown.yml need no change (no new export; summary-level cran-comments already covers Savant column handling).
  • Commits follow Conventional Commits and contain no AI co-author trailers.

Testing

  • devtools::test() passes locally.
  • New/changed behavior is covered by a test using subset-direction column assertions.

Execution time before: N/A
Execution time after: N/A

Screenshots / Output

N/A

Reviewer Checklist

  • Function naming uses the correct data-source prefix.
  • Return value is initialized before tryCatch; error path returns an
    empty value with a cli message rather than erroring.
  • man/ and NAMESPACE are regenerated and consistent with the source.
  • Tests are appropriately gated; no test hammers the NCAA stats site.
  • NEWS.md / cran-comments.md / _pkgdown.yml are consistent for any
    API-surface change.
  • Commit messages are conventional and free of AI co-author trailers.

@saiemgilani
saiemgilani merged commit a884b5c into BillPetti:master Jul 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: BaseballSavant added 119th column (miss_distance)

2 participants