nflverse / nflverse-pfr

builds pfr data for nflverse/nflverse-data
GNU General Public License v3.0
7 stars 1 forks source link

`load_snap_counts()` function has team and opponent fields flipped #29

Closed Josephhero closed 1 year ago

Josephhero commented 1 year ago

Is there an existing issue for this?

Have you installed the latest development version of the package(s) in question?

What version of the package do you have?

nflreadr: 1.3.2

Describe the bug

The load_snap_counts() function is returning the wrong teams for the 2022 Super Bowl between Chiefs and Eagles. The team and opponent fields are flipped (Chiefs players listed as eagles, eagles listed as chiefs).

Reprex

r
library(nflreadr)
library(tidyverse)

nflreadr::.clear_cache()
#> ✔ nflreadr function cache cleared!

df <- load_snap_counts(seasons = 2022) |> 
  filter(week == 22) |> 
  filter(player %in% c('Patrick Mahomes', 'Jalen Hurts'))

df
#> ── nflverse snap counts ────────────────────────────────────────────────────────
#> ℹ Data updated: 2023-02-13 10:28:12 PST
#> # A tibble: 2 × 16
#>   game_id      pfr_g…¹ season game_…²  week player pfr_p…³ posit…⁴ team  oppon…⁵
#>   <chr>        <chr>    <int> <chr>   <int> <chr>  <chr>   <chr>   <chr> <chr>  
#> 1 2022_22_KC_… 202302…   2022 SB         22 Patri… MahoPa… QB      PHI   KC     
#> 2 2022_22_KC_… 202302…   2022 SB         22 Jalen… HurtJa… QB      KC    PHI    
#> # … with 6 more variables: offense_snaps <dbl>, offense_pct <dbl>,
#> #   defense_snaps <dbl>, defense_pct <dbl>, st_snaps <dbl>, st_pct <dbl>, and
#> #   abbreviated variable names ¹​pfr_game_id, ²​game_type, ³​pfr_player_id,
#> #   ⁴​position, ⁵​opponent

Created on 2023-02-16 with reprex v2.0.2


### Expected Behavior

The players should be listed as the correct team, not as their opponents.

### nflverse_sitrep

```r
> nflverse_sitrep()
── System Info ──────────────────────────────────────────────────────────────────────────────────────────────────
• R version 4.1.3 (2022-03-10)   • Running under: macOS 13.2
── nflverse Packages ────────────────────────────────────────────────────────────────────────────────────────────
• nflreadr (1.3.2)  • nflseedR (1.2.0)  • nflplotR (1.1.0)  
• nflfastR (4.5.1)  • nfl4th   (1.0.2)  • nflverse (1.0.2)  
── nflverse Options ─────────────────────────────────────────────────────────────────────────────────────────────
No options set for nflreadr, nflfastR, nflseedR, nfl4th, nflplotR, and nflverse
── nflverse Dependencies ────────────────────────────────────────────────────────────────────────────────────────
• askpass     (1.1)     • hms        (1.1.2)     • proto        (1.0.0)    
• cachem      (1.0.6)   • httr       (1.4.4)     • purrr        (1.0.1)    
• cli         (3.6.0)   • isoband    (0.2.7)     • R6           (2.5.1)    
• codetools   (0.2-19)  • janitor    (2.2.0)     • rappdirs     (0.3.3)    
• colorspace  (2.1-0)   • jsonlite   (1.8.4)     • RColorBrewer (1.1-3)    
• cpp11       (0.4.3)   • labeling   (0.4.2)     • Rcpp         (1.0.10)   
• crayon      (1.5.2)   • lattice    (0.20-45)   • rlang        (1.0.6)    
• curl        (5.0.0)   • lifecycle  (1.0.3)     • rstudioapi   (0.14)     
• data.table  (1.14.6)  • listenv    (0.9.0)     • scales       (1.2.1)    
• digest      (0.6.31)  • lubridate  (1.9.1)     • snakecase    (0.11.0)   
• dplyr       (1.1.0)   • magick     (2.7.3)     • stringi      (1.7.12)   
• ellipsis    (0.3.2)   • magrittr   (2.0.3)     • stringr      (1.5.0)    
• fansi       (1.0.4)   • MASS       (7.3-58.2)  • sys          (3.4.1)    
• farver      (2.1.1)   • Matrix     (1.4-0)     • tibble       (3.1.8)    
• fastmap     (1.1.0)   • memoise    (2.0.1)     • tidyr        (1.3.0)    
• fastrmodels (1.0.2)   • mgcv       (1.8-41)    • tidyselect   (1.2.0)    
• furrr       (0.3.1)   • mime       (0.12)      • timechange   (0.2.0)    
• future      (1.31.0)  • munsell    (0.5.0)     • utf8         (1.2.3)    
• generics    (0.1.3)   • nlme       (3.1-162)   • vctrs        (0.5.2)    
• ggplot2     (3.4.0)   • openssl    (2.0.5)     • viridisLite  (0.4.1)    
• globals     (0.16.2)  • parallelly (1.34.0)    • withr        (2.5.0)    
• glue        (1.6.2)   • pillar     (1.8.1)     • xgboost      (1.7.3.1)  
• gsubfn      (0.7)     • pkgconfig  (2.0.3)       
• gtable      (0.3.1)   • progressr  (0.13.0)

Screenshots

No response

Additional context

No response

mrcaseb commented 1 year ago

PFR seems to be messing up home and away in almost all super bowls. But they fixed it at some point in the offseason. I rescraped it and it's fine now.

nflreadr::load_snap_counts(seasons = 2022) |> 
  dplyr::filter(week == 22) |> 
  dplyr::filter(player %in% c('Patrick Mahomes', 'Jalen Hurts')) |> 
  dplyr::select(
    game_id, player, pfr_player_id, team, opponent
  )
#> ── nflverse snap counts ────────────────────────────────────────────────────────
#> ℹ Data updated: 2023-08-28 16:57:43 CEST
#> # A tibble: 2 × 5
#>   game_id        player          pfr_player_id team  opponent
#>   <chr>          <chr>           <chr>         <chr> <chr>   
#> 1 2022_22_KC_PHI Jalen Hurts     HurtJa00      PHI   KC      
#> 2 2022_22_KC_PHI Patrick Mahomes MahoPa00      KC    PHI

Created on 2023-08-28 with reprex v2.0.2