Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ff_rosters() not working for ESPN leagures #437

Closed
WMRobin opened this issue Sep 20, 2024 · 5 comments
Closed

ff_rosters() not working for ESPN leagures #437

WMRobin opened this issue Sep 20, 2024 · 5 comments

Comments

@WMRobin
Copy link

WMRobin commented Sep 20, 2024

Describe the bug

The ff_rosters() function is not working for my ESPN league, and at least one other individual has had this issue.

Reprex
Load library and open connection:

# install.packages("ffscrapr", repos = c("https://ffverse.r-universe.dev", getOption("repos")))
library(ffscrapr)

# open espn connection
conn <- espn_connect(
  season = Sys.getenv("current_season"),
  league_id = Sys.getenv("league_id"),
  espn_s2 = Sys.getenv("my_espn_2"),
  swid = Sys.getenv("my_swid"),
  user_agent = "Name"
)

I'm using an R project with current_season, league_id, my_espn_2, and my_swid saved to the project's profile.

The following code reads my league's rosters for week 1:

starters_1 <- ff_starters(conn, week = 1)
head(starters_1)
# A tibble: 6 × 12
   week franchise_id franchise_name  franchise_score lineup_slot player_score
  <int>        <int> <chr>                     <dbl> <chr>              <dbl>
1     1            1 Pineapple Juice            102. QB                  14.2
2     1            1 Pineapple Juice            102. RB                  10.8
3     1            1 Pineapple Juice            102. RB                  26.8
4     1            1 Pineapple Juice            102. WR                   8.2
5     1            1 Pineapple Juice            102. WR                   3.6
6     1            1 Pineapple Juice            102. TE                   8.5
# ℹ 6 more variables: projected_score <dbl>, player_id <int>, player_name <chr>,
#   pos <chr>, team <chr>, eligible_lineup_slots <list>

However, when doing the same for week 2, I get the following error:

starters_2 <- ff_starters(conn, week = 2)
head(starters_2)

Error in `map2()`:In index: 1.With name: 2.
Caused by error in `dplyr::mutate()`:In argument: `projected_score = purrr::map2_dbl(...)`.
Caused by error in `purrr::map2_dbl()`:In index: 1.
Caused by error in `pluck_raw()`:
! Index 1 must have length 1, not 2.
Run `rlang::last_trace()` to see where the error occurred.

Expected behavior
I expected the function to return my league's starters for week 2, as it did for week 1.

Session information
Please copy the output of ffscrapr::ffverse_sitrep() into the box below.

ffscrapr::ffverse_sitrep()

── System Info ──────────────────────────────────────────────────────────────────────
• R version 4.4.1 (2024-06-14 ucrt) • Running under: Windows 11 x64 (build 22635)
── Package Status ───────────────────────────────────────────────────────────────────
   package installed  cran      dev behind
1   ffpros     0.1.5  <NA>    0.1.5       
2 ffscrapr  1.4.8.19 1.4.8 1.4.8.19       
── Package Options ──────────────────────────────────────────────────────────────────
• No options set for above packages
── Package Dependencies ─────────────────────────────────────────────────────────────
• askpass    (1.2.0)   • lifecycle  (1.0.4)   • stringi    (1.8.4)  
• assertthat (0.2.1)   • lubridate  (1.9.3)   • stringr    (1.5.1)  
• backports  (1.5.0)   • magrittr   (2.0.3)   • sys        (3.4.2)  
• cachem     (1.1.0)   • memoise    (2.0.1)   • tibble     (3.2.1)  
• checkmate  (2.3.1)   • mime       (0.12)    • tidyr      (1.3.1)  
• cli        (3.6.3)   • nflreadr   (1.4.1)   • tidyselect (1.2.1)  
• cpp11      (0.4.7)   • openssl    (2.2.0)   • timechange (0.3.0)  
• curl       (5.2.1)   • pillar     (1.9.0)   • utf8       (1.2.4)  
• data.table (1.15.4)  • pkgconfig  (2.0.3)   • V8         (5.0.0)  
• dplyr      (1.1.4)   • purrr      (1.0.2)   • vctrs      (0.6.5)  
• fansi      (1.0.6)   • R6         (2.5.1)   • withr      (3.0.0)  
• fastmap    (1.2.0)   • rappdirs   (0.3.3)   • xml2       (1.3.6)  
• generics   (0.1.3)   • ratelimitr (0.4.1)   • graphics   (4.4.1)  
• glue       (1.7.0)   • Rcpp       (1.0.12)  • grDevices  (4.4.1)  
• hms        (1.1.3)   • rlang      (1.1.4)   • methods    (4.4.1)  
• httr       (1.4.7)   • rvest      (1.0.4)   • stats      (4.4.1)  
• janitor    (2.2.0)   • selectr    (0.4-2)   • tools      (4.4.1)  
• jsonlite   (1.8.8)   • snakecase  (0.11.1)  • utils      (4.4.1)  
── Not Installed ────────────────────────────────────────────────────────────────────
• ffsimulator   ()
• ffopportunity ()
─────────────────────────────────────────────────────────────────────────────────────
@WMRobin
Copy link
Author

WMRobin commented Sep 20, 2024

For more context, this issue is not unique to ff_starters().
The same issue occurs with espn_potentialpoints(), so maybe this is a result of something affecting all data for weeks > 1.
To be clear, I get the following output using the same connection as the reprex above:

espn_potentialpoints(conn, week = 1)
# A tibble: 193 × 11
    week franchise_id franchise_name  franchise_score optimal_slot actual_slot
   <int>        <int> <chr>                     <dbl> <chr>        <chr>      
 1     1            1 Pineapple Juice            102. QB           QB         
 2     1            1 Pineapple Juice            102. RB           RB         
 3     1            1 Pineapple Juice            102. RB           BE         
 4     1            1 Pineapple Juice            102. WR           BE         
 5     1            1 Pineapple Juice            102. WR           WR         
 6     1            1 Pineapple Juice            102. TE           TE         
 7     1            1 Pineapple Juice            102. RB/WR/TE     RB         
 8     1            1 Pineapple Juice            102. DST          DST        
 9     1            1 Pineapple Juice            102. K            K          
10     1            1 Pineapple Juice            102. NA           BE         
# ℹ 183 more rows
# ℹ 5 more variables: player_score <dbl>, player_name <chr>, player_pos <chr>,
#   team <chr>, player_id <int>
# ℹ Use `print(n = ...)` to see more rows

espn_potentialpoints(conn, week = 2)
Error in `map2()`:In index: 1.With name: 2.
Caused by error in `dplyr::mutate()`:In argument: `projected_score = purrr::map2_dbl(...)`.
Caused by error in `purrr::map2_dbl()`:In index: 1.
Caused by error in `pluck_raw()`:
! Index 1 must have length 1, not 2.
Run `rlang::last_trace()` to see where the error occurred.

@tanho63
Copy link
Member

tanho63 commented Sep 20, 2024

this issue is not unique to ff_starters()

not quite, potentialpoints calls ff_starters as its very first line
https://github.com/ffverse/ffscrapr/blob/main/R/espn_potentialpoints.R#L22

@TheMathNinja
Copy link
Contributor

There's been a bit of ESPN API wonkiness as of late. I encountered this: cwendt94/espn-api#575

@WMRobin
Copy link
Author

WMRobin commented Sep 26, 2024

I wanted to update this to say that ff_starters() is working for me now.

The following code

# install.packages("ffscrapr", repos = c("https://ffverse.r-universe.dev", getOption("repos")))
library(ffscrapr)

# open espn connection
conn <- espn_connect(
  season = Sys.getenv("current_season"),
  league_id = Sys.getenv("league_id"),
  espn_s2 = Sys.getenv("my_espn_2"),
  swid = Sys.getenv("my_swid"),
  user_agent = "Name"
)

starters_1 <- ff_starters(conn, week = 1)
starters_2 <- ff_starters(conn, week = 2)

head(starters_1)
head(starters_2)

gives me the output

# A tibble: 6 × 12
   week franchise_id franchise_name  franchise_score lineup_slot player_score
  <int>        <int> <chr>                     <dbl> <chr>              <dbl>
1     1            1 Pineapple Juice            102. QB                  14.2
2     1            1 Pineapple Juice            102. RB                  10.8
3     1            1 Pineapple Juice            102. RB                  26.8
4     1            1 Pineapple Juice            102. WR                   8.2
5     1            1 Pineapple Juice            102. WR                   3.6
6     1            1 Pineapple Juice            102. TE                   8.5
# ℹ 6 more variables: projected_score <dbl>, player_id <int>, player_name <chr>,
#   pos <chr>, team <chr>, eligible_lineup_slots <list>
> head(starters_2)
# A tibble: 6 × 12
   week franchise_id franchise_name  franchise_score lineup_slot player_score
  <int>        <int> <chr>                     <dbl> <chr>              <dbl>
1     2            1 Pineapple Juice            103. QB                  28.5
2     2            1 Pineapple Juice            103. RB                  15.5
3     2            1 Pineapple Juice            103. RB                   8  
4     2            1 Pineapple Juice            103. WR                   4.1
5     2            1 Pineapple Juice            103. WR                  12.8
6     2            1 Pineapple Juice            103. TE                   3.3
# ℹ 6 more variables: projected_score <dbl>, player_id <int>, player_name <chr>,
#   pos <chr>, team <chr>, eligible_lineup_slots <list>

as expected.

@tanho63
Copy link
Member

tanho63 commented Sep 26, 2024

Great!

@tanho63 tanho63 closed this as completed Sep 26, 2024
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

No branches or pull requests

3 participants