jthomasmock / espnscrapeR

Scrapes Or Collects NFL Data From ESPN
https://jthomasmock.github.io/espnscrapeR/
Other
51 stars 10 forks source link

`scrape_team_stats_nfl` gives error when `role="defense"` #21

Closed bmacGTPM closed 1 year ago

bmacGTPM commented 1 year ago

When I try this

scrape_team_stats_nfl(season = 2022, stats = "passing", role = "defense")

I get this error

Error in `purrr::set_names()`:
! The size of `nm` (15) must be compatible with the size of `x` (11).

A similar error occurs when stats is changed to rushing, scoring, or downs. When stats = "receiving", there is a different error. In particular, this code

scrape_team_stats_nfl(season = season, stats = "receiving", role = "defense")

gives this error

Error in rvest::html_table(raw_html, fill = TRUE)[[1]] : 
  subscript out of bounds

The code works well for all 5 choices of stats when role="offense". The errors only happen when role="defense".

jthomasmock commented 1 year ago

They changed the available columns for defense 👀

jthomasmock commented 1 year ago

Rolled up a new fix.

espnscrapeR::scrape_team_stats_nfl(season = 2022, role = "defense")
Scraping passing for defense from 2022!
# A tibble: 32 × 14
   season role    stat    team       pass_att pass_comp pass_comp_pct yds_att pass_yds pass_td   int first_downs
    <int> <chr>   <chr>   <chr>         <int>     <int>         <dbl>   <dbl>    <int>   <int> <int>       <int>
 1   2022 DEFENSE PASSING Buccaneer…      570       364         0.639     6.1     3461      29    10         186
 2   2022 DEFENSE PASSING ChargersC…      505       310         0.614     6.7     3406      24    14         175
 3   2022 DEFENSE PASSING VikingsVi…      617       408         0.661     7.3     4515      23    15         224
 4   2022 DEFENSE PASSING Cardinals…      593       414         0.698     6.6     3915      29    11         218
 5   2022 DEFENSE PASSING ChiefsChi…      619       408         0.659     6.1     3756      33    11         207
 6   2022 DEFENSE PASSING JetsJets        556       347         0.624     5.8     3220      15    12         166
 7   2022 DEFENSE PASSING BengalsBe…      559       329         0.589     6.6     3665      17    13         173
 8   2022 DEFENSE PASSING ColtsColts      537       365         0.68      6.6     3569      25    10         184
 9   2022 DEFENSE PASSING JaguarsJa…      601       385         0.641     6.8     4055      25    14         211
10   2022 DEFENSE PASSING LionsLions      560       353         0.63      7.5     4179      26    12         209
# ℹ 22 more rows
# ℹ 2 more variables: pass_first_pct <dbl>, sacks <int>
# ℹ Use `print(n = ...)` to see more rows