Skip to contents

Acquire pitch-by-pitch data between two timecodes for Major and Minor League games

Usage

mlb_pbp_diff(game_pk, start_timecode, end_timecode)

Arguments

game_pk

The date for which you want to find game_pk values for MLB games

start_timecode

The start time code for the MLB game (format: MMDDYYYY_HHMMSS)

end_timecode

The end time code for the MLB game (format: MMDDYYYY_HHMMSS)

Value

Returns a tibble that includes over 100 columns of data provided by the MLB Stats API at a pitch level between the start_timecode and end_timecode

col_nametypesdescription
game_pknumericMLB game primary key.
game_datecharacterGame date (YYYY-MM-DD).
indexintegerIndex of the play event within the at-bat.
startTimecharacterEvent start timestamp (ISO 8601).
endTimecharacterEvent end timestamp (ISO 8601).
isPitchlogicalWhether the event is a pitch.
typecharacterPlay event type (e.g. 'pitch', 'action').
playIdcharacterUnique play event identifier (UUID).
pitchNumberintegerPitch number within the at-bat.
details.descriptioncharacterPitch/event description (e.g. 'Foul', 'Ball').
details.eventcharacterEvent name for non-pitch actions.
details.awayScoreintegerAway score recorded at the event.
details.homeScoreintegerHome score recorded at the event.
details.isScoringPlaylogicalWhether the event is a scoring play.
details.hasReviewlogicalWhether the event was reviewed.
details.codecharacterPitch/result code (e.g. 'F', 'B').
details.ballColorcharacterGameday ball color rgba string.
details.isInPlaylogicalWhether the ball was put in play.
details.isStrikelogicalWhether the pitch was a strike.
details.isBalllogicalWhether the pitch was a ball.
details.call.codecharacterUmpire call code.
details.call.descriptioncharacterUmpire call description.
count.balls.startintegerBall count before the pitch.
count.strikes.startintegerStrike count before the pitch.
count.outs.startintegerOut count before the pitch.
player.idintegerPlayer id for action-event participant.
player.linkcharacterAPI relative link to the action player.
pitchData.strikeZoneTopnumericTop of the batter strike zone (feet).
pitchData.strikeZoneBottomnumericBottom of the batter strike zone (feet).
details.fromCatcherlogicalWhether the event originated from the catcher.
pitchData.coordinates.xnumericPitch x pixel coordinate (Gameday).
pitchData.coordinates.ynumericPitch y pixel coordinate (Gameday).
hitData.trajectorycharacterBatted ball trajectory.
hitData.hardnesscharacterBatted ball hardness.
hitData.locationcharacterFielding position where the ball was hit.
hitData.coordinates.coordXnumericBatted ball landing x coordinate.
hitData.coordinates.coordYnumericBatted ball landing y coordinate.
actionPlayIdcharacterIdentifier of an associated action play.
details.eventTypecharacterEvent type slug for non-pitch actions.
details.runnerGoinglogicalWhether a runner was going on the pitch.
position.codecharacterFielding position code for the player.
position.namecharacterFielding position name.
position.typecharacterFielding position type.
position.abbreviationcharacterFielding position abbreviation.
battingOrdercharacterBatting order slot.
atBatIndexcharacterAt-bat index within the game (factor).
result.typecharacterResult type (e.g. 'atBat').
result.eventcharacterAt-bat result event.
result.eventTypecharacterAt-bat result event slug.
result.descriptioncharacterNarrative description of the at-bat result.
result.rbiintegerRuns batted in on the at-bat.
result.awayScoreintegerAway score after the at-bat.
result.homeScoreintegerHome score after the at-bat.
about.atBatIndexintegerAt-bat index (numeric).
about.halfInningcharacterHalf inning ('top' or 'bottom').
about.inningintegerInning number.
about.startTimecharacterAt-bat start timestamp (ISO 8601).
about.endTimecharacterAt-bat end timestamp (ISO 8601).
about.isCompletelogicalWhether the at-bat is complete.
about.isScoringPlaylogicalWhether the at-bat is a scoring play.
about.hasReviewlogicalWhether the at-bat had a review.
about.hasOutlogicalWhether the at-bat produced an out.
about.captivatingIndexintegerMLB captivating index for the play.
count.balls.endintegerBall count after the pitch.
count.strikes.endintegerStrike count after the pitch.
count.outs.endintegerOut count after the pitch.
matchup.batter.idintegerBatter player id.
matchup.batter.fullNamecharacterBatter full name (factor).
matchup.batter.linkcharacterAPI relative link to the batter.
matchup.batSide.codecharacterBatter handedness code (e.g. 'L', 'R').
matchup.batSide.descriptioncharacterBatter handedness description.
matchup.pitcher.idintegerPitcher player id.
matchup.pitcher.fullNamecharacterPitcher full name (factor).
matchup.pitcher.linkcharacterAPI relative link to the pitcher.
matchup.pitchHand.codecharacterPitcher throwing hand code (e.g. 'R').
matchup.pitchHand.descriptioncharacterPitcher throwing hand description.
matchup.splits.battercharacterBatter platoon split (e.g. 'vs_RHP').
matchup.splits.pitchercharacterPitcher platoon split (e.g. 'vs_RHB').
matchup.splits.menOnBasecharacterMen on base split (e.g. 'Men_On').
batted.ball.resultfactorCategorized batted ball result.
home_teamcharacterHome team name.
home_level_idintegerHome team level/sport id (1 for MLB).
home_level_namecharacterHome team level/sport name.
home_parentOrg_idintegerHome team parent organization id (minors).
home_parentOrg_namecharacterHome team parent organization name (minors).
home_league_idintegerHome team league id.
home_league_namecharacterHome team league name.
away_teamcharacterAway team name.
away_level_idintegerAway team level/sport id (1 for MLB).
away_level_namecharacterAway team level/sport name.
away_parentOrg_idintegerAway team parent organization id (minors).
away_parentOrg_namecharacterAway team parent organization name (minors).
away_league_idintegerAway team league id.
away_league_namecharacterAway team league name.
batting_teamcharacterTeam batting on the play (factor).
fielding_teamcharacterTeam fielding on the play (factor).
last.pitch.of.abcharacterWhether the pitch was the last of the at-bat (factor).
pfxIdcharacterPitch f/x tracking identifier.
details.trailColorcharacterGameday pitch trail color rgba string.
details.type.codecharacterPitch type code (e.g. 'SI', 'CH').
details.type.descriptioncharacterPitch type description (e.g. 'Sinker', 'Changeup').
pitchData.startSpeednumericPitch release speed (mph).
pitchData.endSpeednumericPitch speed crossing the plate (mph).
pitchData.zoneintegerStrike zone region of the pitch.
pitchData.typeConfidencenumericPitch type classification confidence.
pitchData.plateTimenumericTime from release to plate (seconds).
pitchData.extensionnumericPitcher release extension (feet).
pitchData.coordinates.aYnumericPitch acceleration in y (ft/s^2).
pitchData.coordinates.aZnumericPitch acceleration in z (ft/s^2).
pitchData.coordinates.pfxXnumericHorizontal pitch movement (inches).
pitchData.coordinates.pfxZnumericVertical pitch movement (inches).
pitchData.coordinates.pXnumericHorizontal pitch location at plate (feet).
pitchData.coordinates.pZnumericVertical pitch location at plate (feet).
pitchData.coordinates.vX0numericPitch initial velocity in x (ft/s).
pitchData.coordinates.vY0numericPitch initial velocity in y (ft/s).
pitchData.coordinates.vZ0numericPitch initial velocity in z (ft/s).
pitchData.coordinates.x0numericPitch initial x position (feet).
pitchData.coordinates.y0numericPitch initial y position (feet).
pitchData.coordinates.z0numericPitch initial z position (feet).
pitchData.coordinates.aXnumericPitch acceleration in x (ft/s^2).
pitchData.breaks.breakAnglenumericPitch break angle (degrees).
pitchData.breaks.breakLengthnumericPitch break length (inches).
pitchData.breaks.breakYnumericDistance from plate where break is measured.
pitchData.breaks.spinRateintegerPitch spin rate (RPM).
pitchData.breaks.spinDirectionintegerPitch spin direction (degrees).
hitData.launchSpeednumericBatted ball exit velocity (mph).
hitData.launchAnglenumericBatted ball launch angle (degrees).
hitData.totalDistancenumericBatted ball total distance (feet).
injuryTypecharacterInjury type when the event is injury-related.
umpire.idintegerUmpire person id for the event.
umpire.linkcharacterAPI relative link to the umpire.
details.isOutlogicalWhether the pitch/event resulted in an out.
pitchData.breaks.breakVerticalnumericTotal vertical break (inches).
pitchData.breaks.breakVerticalInducednumericInduced vertical break (inches).
pitchData.breaks.breakHorizontalnumericHorizontal break (inches).
details.disengagementNumintegerPitcher disengagement number on the play.
result.isOutlogicalWhether the at-bat resulted in an out.
about.isTopInninglogicalWhether the play occurred in the top of the inning.
matchup.postOnFirst.idintegerRunner id on first base after the play.
matchup.postOnFirst.fullNamecharacterRunner name on first base after the play.
matchup.postOnFirst.linkcharacterAPI relative link to the first base runner.

Examples

# \donttest{
  try(mlb_pbp_diff(game_pk = 632970, 
                   start_timecode = "20210808_231704", 
                   end_timecode = "20210808_233711"))
#> ── MLB Play-by-Play diff data from MLB.com ────────── baseballr 2.0.0 ──
#>  Data updated: 2026-06-12 14:09:44 UTC
#> # A tibble: 50 × 141
#>    game_pk game_date  index startTime       endTime isPitch type  playId
#>      <dbl> <chr>      <int> <chr>           <chr>   <lgl>   <chr> <chr> 
#>  1  632970 2021-08-08     2 2021-08-08T23:… 2021-0… TRUE    pitch 0c67e…
#>  2  632970 2021-08-08     1 2021-08-08T23:… 2021-0… TRUE    pitch 51631…
#>  3  632970 2021-08-08     0 2021-08-08T23:… 2021-0… TRUE    pitch e3edf…
#>  4  632970 2021-08-08     2 2021-08-08T23:… 2021-0… TRUE    pitch 65870…
#>  5  632970 2021-08-08     1 2021-08-08T23:… 2021-0… TRUE    pitch d5fc8…
#>  6  632970 2021-08-08     0 2021-08-08T23:… 2021-0… TRUE    pitch 0a6c9…
#>  7  632970 2021-08-08     4 2021-08-08T23:… 2021-0… TRUE    pitch 506d0…
#>  8  632970 2021-08-08     3 2021-08-08T23:… 2021-0… TRUE    pitch 24f33…
#>  9  632970 2021-08-08     2 2021-08-08T23:… 2021-0… TRUE    pitch aae6b…
#> 10  632970 2021-08-08     1 2021-08-08T23:… 2021-0… TRUE    pitch 63658…
#> # ℹ 40 more rows
#> # ℹ 133 more variables: pitchNumber <int>, details.description <chr>,
#> #   details.event <chr>, details.awayScore <int>,
#> #   details.homeScore <int>, details.isScoringPlay <lgl>,
#> #   details.hasReview <lgl>, details.code <chr>,
#> #   details.ballColor <chr>, details.isInPlay <lgl>,
#> #   details.isStrike <lgl>, details.isBall <lgl>, …
# }