Skip to contents

This function allows you to query Statcast data as provided on https://baseballsavant.mlb.com

Usage

statcast_search(
  start_date = Sys.Date() - 1,
  end_date = Sys.Date(),
  playerid = NULL,
  player_type = "batter",
  ...
)

statcast_search.default(
  start_date = Sys.Date() - 1,
  end_date = Sys.Date(),
  playerid = NULL,
  player_type = "batter",
  ...
)

statcast_search_batters(start_date, end_date, batterid = NULL, ...)

statcast_search_pitchers(start_date, end_date, pitcherid = NULL, ...)

Arguments

start_date

Date of first game for which you want data. Format must be in YYYY-MM-DD format.

end_date

Date of last game for which you want data. Format must be in YYYY-MM-DD format.

playerid

The MLBAM ID for the player whose data you want to query.

player_type

The player type. Can be batter or pitcher. Default is batter

...

currently ignored

batterid

The MLBAM ID for the batter whose data you want to query.

pitcherid

The MLBAM ID for the pitcher whose data you want to query.

Value

Returns a tibble with Statcast data with the following columns:

col_nametypes
pitch_typecharacter
game_dateDate
release_speednumeric
release_pos_xnumeric
release_pos_znumeric
player_namecharacter
batternumeric
pitchernumeric
eventscharacter
descriptioncharacter
spin_dirlogical
spin_rate_deprecatedlogical
break_angle_deprecatedlogical
break_length_deprecatedlogical
zonenumeric
descharacter
game_typecharacter
standcharacter
p_throwscharacter
home_teamcharacter
away_teamcharacter
typecharacter
hit_locationinteger
bb_typecharacter
ballsinteger
strikesinteger
game_yearinteger
pfx_xnumeric
pfx_znumeric
plate_xnumeric
plate_znumeric
on_3bnumeric
on_2bnumeric
on_1bnumeric
outs_when_upinteger
inningnumeric
inning_topbotcharacter
hc_xnumeric
hc_ynumeric
tfs_deprecatedlogical
tfs_zulu_deprecatedlogical
fielder_2numeric
umpirelogical
sv_idcharacter
vx0numeric
vy0numeric
vz0numeric
axnumeric
aynumeric
aznumeric
sz_topnumeric
sz_botnumeric
hit_distance_scnumeric
launch_speednumeric
launch_anglenumeric
effective_speednumeric
release_spin_ratenumeric
release_extensionnumeric
game_pknumeric
pitcher_1numeric
fielder_2_1numeric
fielder_3numeric
fielder_4numeric
fielder_5numeric
fielder_6numeric
fielder_7numeric
fielder_8numeric
fielder_9numeric
release_pos_ynumeric
estimated_ba_using_speedanglenumeric
estimated_woba_using_speedanglenumeric
woba_valuenumeric
woba_denominteger
babip_valueinteger
iso_valueinteger
launch_speed_angleinteger
at_bat_numbernumeric
pitch_numbernumeric
pitch_namecharacter
home_scorenumeric
away_scorenumeric
bat_scorenumeric
fld_scorenumeric
post_away_scorenumeric
post_home_scorenumeric
post_bat_scorenumeric
post_fld_scorenumeric
if_fielding_alignmentcharacter
of_fielding_alignmentcharacter
spin_axisnumeric
delta_home_win_expnumeric
delta_run_expnumeric

Returns a tibble with Statcast data.

Returns a tibble with Statcast data with the following columns:

col_nametypes
pitch_typecharacter
game_dateDate
release_speednumeric
release_pos_xnumeric
release_pos_znumeric
player_namecharacter
batternumeric
pitchernumeric
eventscharacter
descriptioncharacter
spin_dirlogical
spin_rate_deprecatedlogical
break_angle_deprecatedlogical
break_length_deprecatedlogical
zonenumeric
descharacter
game_typecharacter
standcharacter
p_throwscharacter
home_teamcharacter
away_teamcharacter
typecharacter
hit_locationinteger
bb_typecharacter
ballsinteger
strikesinteger
game_yearinteger
pfx_xnumeric
pfx_znumeric
plate_xnumeric
plate_znumeric
on_3bnumeric
on_2bnumeric
on_1bnumeric
outs_when_upinteger
inningnumeric
inning_topbotcharacter
hc_xnumeric
hc_ynumeric
tfs_deprecatedlogical
tfs_zulu_deprecatedlogical
fielder_2numeric
umpirelogical
sv_idcharacter
vx0numeric
vy0numeric
vz0numeric
axnumeric
aynumeric
aznumeric
sz_topnumeric
sz_botnumeric
hit_distance_scnumeric
launch_speednumeric
launch_anglenumeric
effective_speednumeric
release_spin_ratenumeric
release_extensionnumeric
game_pknumeric
pitcher_1numeric
fielder_2_1numeric
fielder_3numeric
fielder_4numeric
fielder_5numeric
fielder_6numeric
fielder_7numeric
fielder_8numeric
fielder_9numeric
release_pos_ynumeric
estimated_ba_using_speedanglenumeric
estimated_woba_using_speedanglenumeric
woba_valuenumeric
woba_denominteger
babip_valueinteger
iso_valueinteger
launch_speed_angleinteger
at_bat_numbernumeric
pitch_numbernumeric
pitch_namecharacter
home_scorenumeric
away_scorenumeric
bat_scorenumeric
fld_scorenumeric
post_away_scorenumeric
post_home_scorenumeric
post_bat_scorenumeric
post_fld_scorenumeric
if_fielding_alignmentcharacter
of_fielding_alignmentcharacter
spin_axisnumeric
delta_home_win_expnumeric
delta_run_expnumeric

Returns a tibble with Statcast data with the following columns:

col_nametypes
pitch_typecharacter
game_dateDate
release_speednumeric
release_pos_xnumeric
release_pos_znumeric
player_namecharacter
batternumeric
pitchernumeric
eventscharacter
descriptioncharacter
spin_dirlogical
spin_rate_deprecatedlogical
break_angle_deprecatedlogical
break_length_deprecatedlogical
zonenumeric
descharacter
game_typecharacter
standcharacter
p_throwscharacter
home_teamcharacter
away_teamcharacter
typecharacter
hit_locationinteger
bb_typecharacter
ballsinteger
strikesinteger
game_yearinteger
pfx_xnumeric
pfx_znumeric
plate_xnumeric
plate_znumeric
on_3bnumeric
on_2bnumeric
on_1bnumeric
outs_when_upinteger
inningnumeric
inning_topbotcharacter
hc_xnumeric
hc_ynumeric
tfs_deprecatedlogical
tfs_zulu_deprecatedlogical
fielder_2numeric
umpirelogical
sv_idcharacter
vx0numeric
vy0numeric
vz0numeric
axnumeric
aynumeric
aznumeric
sz_topnumeric
sz_botnumeric
hit_distance_scnumeric
launch_speednumeric
launch_anglenumeric
effective_speednumeric
release_spin_ratenumeric
release_extensionnumeric
game_pknumeric
pitcher_1numeric
fielder_2_1numeric
fielder_3numeric
fielder_4numeric
fielder_5numeric
fielder_6numeric
fielder_7numeric
fielder_8numeric
fielder_9numeric
release_pos_ynumeric
estimated_ba_using_speedanglenumeric
estimated_woba_using_speedanglenumeric
woba_valuenumeric
woba_denominteger
babip_valueinteger
iso_valueinteger
launch_speed_angleinteger
at_bat_numbernumeric
pitch_numbernumeric
pitch_namecharacter
home_scorenumeric
away_scorenumeric
bat_scorenumeric
fld_scorenumeric
post_away_scorenumeric
post_home_scorenumeric
post_bat_scorenumeric
post_fld_scorenumeric
if_fielding_alignmentcharacter
of_fielding_alignmentcharacter
spin_axisnumeric
delta_home_win_expnumeric
delta_run_expnumeric

Examples

# \donttest{
  ### Harper
  try(statcast_search(start_date = "2022-10-06", 
                      end_date = "2022-10-16", 
                      playerid = 547180, 
                      player_type = 'batter'))
#> ── MLB Baseball Savant Statcast Search data from baseballsavant.mlb.com 
#>  Data updated: 2022-12-29 00:09:13 UTC
#> # A tibble: 78 × 92
#>    pitch_type game_date  releas…¹ relea…² relea…³ playe…⁴ batter pitcher
#>    <chr>      <date>        <dbl>   <dbl>   <dbl> <chr>    <dbl>   <dbl>
#>  1 FF         2022-10-15     96.4   -2.61    5.49 Harper… 547180  450203
#>  2 CU         2022-10-15     83.3   -2.7     5.36 Harper… 547180  450203
#>  3 FF         2022-10-15     96.2   -2.72    5.57 Harper… 547180  450203
#>  4 FF         2022-10-15     96.1   -2.67    5.39 Harper… 547180  450203
#>  5 FF         2022-10-15     95.8   -2.62    5.45 Harper… 547180  450203
#>  6 FC         2022-10-15     93.4   -1.05    6.88 Harper… 547180  445276
#>  7 FC         2022-10-15     93.1   -1.16    6.87 Harper… 547180  445276
#>  8 FF         2022-10-15     95.8   -1.47    5.64 Harper… 547180  628452
#>  9 FC         2022-10-15     92.3   -1.1     6.86 Harper… 547180  445276
#> 10 FC         2022-10-15     91     -2.09    5.64 Harper… 547180  543521
#> # … with 68 more rows, 84 more variables: events <chr>,
#> #   description <chr>, spin_dir <lgl>, spin_rate_deprecated <lgl>,
#> #   break_angle_deprecated <lgl>, break_length_deprecated <lgl>,
#> #   zone <dbl>, des <chr>, game_type <chr>, stand <chr>,
#> #   p_throws <chr>, home_team <chr>, away_team <chr>, type <chr>,
#> #   hit_location <int>, bb_type <chr>, balls <int>, strikes <int>,
#> #   game_year <int>, pfx_x <dbl>, pfx_z <dbl>, plate_x <dbl>, …
  ### Framber
  try(statcast_search(start_date = "2022-10-06", 
                      end_date = "2022-10-16", 
                      playerid = 664285, 
                      player_type = 'pitcher'))
#> ── MLB Baseball Savant Statcast Search data from baseballsavant.mlb.com 
#>  Data updated: 2022-12-29 00:09:13 UTC
#> # A tibble: 92 × 92
#>    pitch_type game_date  releas…¹ relea…² relea…³ playe…⁴ batter pitcher
#>    <chr>      <date>        <dbl>   <dbl>   <dbl> <chr>    <dbl>   <dbl>
#>  1 CU         2022-10-13     78.1    1.09    6.06 Valdez… 664238  664285
#>  2 SI         2022-10-13     94.7    0.86    6.15 Valdez… 664238  664285
#>  3 CU         2022-10-13     79.4    0.95    6.02 Valdez… 664238  664285
#>  4 CU         2022-10-13     79.1    1.04    6.19 Valdez… 664238  664285
#>  5 CU         2022-10-13     81.4    0.93    6.06 Valdez… 664238  664285
#>  6 CU         2022-10-13     80.6    1.03    6.05 Valdez… 664238  664285
#>  7 SI         2022-10-13     95.4    0.71    6.19 Valdez… 467793  664285
#>  8 CU         2022-10-13     80.6    0.86    6.11 Valdez… 571745  664285
#>  9 CH         2022-10-13     91.6    0.73    6.19 Valdez… 571745  664285
#> 10 CU         2022-10-13     81      0.84    6.13 Valdez… 571745  664285
#> # … with 82 more rows, 84 more variables: events <chr>,
#> #   description <chr>, spin_dir <lgl>, spin_rate_deprecated <lgl>,
#> #   break_angle_deprecated <lgl>, break_length_deprecated <lgl>,
#> #   zone <dbl>, des <chr>, game_type <chr>, stand <chr>,
#> #   p_throws <chr>, home_team <chr>, away_team <chr>, type <chr>,
#> #   hit_location <int>, bb_type <chr>, balls <int>, strikes <int>,
#> #   game_year <int>, pfx_x <dbl>, pfx_z <dbl>, plate_x <dbl>, …
  ### Daily
  try(statcast_search(start_date = "2022-11-04", 
                      end_date = "2022-11-06"))
#> ── MLB Baseball Savant Statcast Search data from baseballsavant.mlb.com 
#>  Data updated: 2022-12-29 00:09:13 UTC
#> # A tibble: 250 × 92
#>    pitch_type game_date  releas…¹ relea…² relea…³ playe…⁴ batter pitcher
#>    <chr>      <date>        <dbl>   <dbl>   <dbl> <chr>    <dbl>   <dbl>
#>  1 CU         2022-11-05     80.8    1.01    6.1  Harper… 547180  664285
#>  2 FC         2022-11-05     85.3    0.96    6.13 Harper… 547180  664285
#>  3 SI         2022-11-05     95.7    0.73    6.3  Harper… 547180  664285
#>  4 FC         2022-11-05     84.5    1.09    6.04 Harper… 547180  664285
#>  5 CU         2022-11-05     79.1    0.99    6.2  Realmu… 592663  664285
#>  6 CH         2022-11-05     87.5    1.04    6.16 Realmu… 592663  664285
#>  7 SI         2022-11-05     94.3    0.99    6.26 Hoskin… 656555  664285
#>  8 CU         2022-11-05     78.9    1.09    6.13 Hoskin… 656555  664285
#>  9 CU         2022-11-05     81.1    1.25    6.18 Hoskin… 656555  664285
#> 10 SI         2022-11-05     95.7    0.62    6.34 Schwar… 656941  664285
#> # … with 240 more rows, 84 more variables: events <chr>,
#> #   description <chr>, spin_dir <lgl>, spin_rate_deprecated <lgl>,
#> #   break_angle_deprecated <lgl>, break_length_deprecated <lgl>,
#> #   zone <dbl>, des <chr>, game_type <chr>, stand <chr>,
#> #   p_throws <chr>, home_team <chr>, away_team <chr>, type <chr>,
#> #   hit_location <int>, bb_type <chr>, balls <int>, strikes <int>,
#> #   game_year <int>, pfx_x <dbl>, pfx_z <dbl>, plate_x <dbl>, …
# }
# \donttest{
  correa <- statcast_search_batters(start_date = "2016-04-06",
    end_date = "2016-04-15", batterid = 621043)
  daily <- statcast_search_batters(start_date = "2016-04-06",
    end_date = "2016-04-06", batterid = NULL)
# }
# \donttest{
  x <- statcast_search_pitchers(start_date = "2016-04-06",
    end_date = "2016-04-15", pitcherid = 592789)
  daily <- statcast_search_pitchers(start_date = "2016-04-06",
    end_date = "2016-04-06", pitcherid = NULL)
# }