Skip to content

Expected columns from ESPN cause uncaught error when missing #297

@jpiburn

Description

@jpiburn

When connecting to current year 2021 leagues, many of the ff_ family of functions result in an uncaught error due to there being no information available at those endpoints before the draft and rosters are initialized.

It looks like most of them are related to column values being NA when it is expected to be a list column containing the (usually populated) data. For example ff_rosters() throws an error here

I only checked the ESPN related functions, so not sure if other sites have any of the same pre-draft issues.

library(ffscrapr)

# sucioboys league from espn basics article
conn <- espn_connect(season = 2021, league_id = 899513)

# expected list column not present -----
ff_starters(conn)
#> Error: `col` must be a list-column
ff_transactions(conn)
#> Request failed [401]. Retrying in 1 seconds...
#> Request failed [401]. Retrying in 2.8 seconds...
#> Warning: ESPN API request failed with error: <401> 
#> 
#> while calling <https://fantasy.espn.com/apis/v3/games/ffl/seasons/2021/segments/0/leagues/899513/communication/?view=kona_league_communication>
#> Error: `col` must be a list-column
ff_starters(conn)
#> Error: `col` must be a list-column
espn_potentialpoints(conn)
#> Error: `col` must be a list-column

# `completeDate` field not found -----
ff_draft(conn) 
#> Error: Problem with `mutate()` column `completeDate`.
#> i `completeDate = lubridate::as_datetime(.data$completeDate/1000)`.
#> x error in evaluating the argument 'x' in selecting a method for function 'as_datetime': Column `completeDate` not found in `.data`

# works as expected -----
# ff_franchises(conn)
# ff_league(conn)
# ff_playerscores(conn)
# ff_schedule(conn)
# ff_scoring(conn)
# ff_scoringhistory(conn)
# ff_standings(conn)
# ff_starter_positions(conn)

# works as expected b/c keeper league has roster -----
ff_rosters(conn)
#> # A tibble: 224 x 10
#>    franchise_id franchise_name player_id player_name    team  pos   eligible_pos
#>           <int> <chr>              <int> <chr>          <chr> <chr> <list>      
#>  1            1 The Early GGod   4036348 Michael Gallup DAL   WR    <chr [7]>   
#>  2            1 The Early GGod   4036131 Noah Fant      DEN   TE    <chr [6]>   
#>  3            1 The Early GGod    -16003 Bears D/ST     CHI   DST   <chr [3]>   
#>  4            1 The Early GGod     15920 Latavius Murr~ NOS   RB    <chr [6]>   
#>  5            1 The Early GGod   3055899 Harrison Butk~ KCC   K     <chr [3]>   
#>  6            1 The Early GGod   4241372 Marquise Brown BAL   WR    <chr [7]>   
#>  7            1 The Early GGod   2976316 Michael Thomas NOS   WR    <chr [7]>   
#>  8            1 The Early GGod   2577327 Tyler Lockett  SEA   WR    <chr [7]>   
#>  9            1 The Early GGod   2977644 Todd Gurley II FA    RB    <chr [6]>   
#> 10            1 The Early GGod   3916925 Kerryon Johns~ PHI   RB    <chr [6]>   
#> # ... with 214 more rows, and 3 more variables: status <chr>,
#> #   acquisition_type <chr>, acquisition_date <dttm>

# but redraft league fails (couldn't find public redraft id, using my league)
conn_redraft <- espn_connect(
  season = 2021,
  league_id = 973,
  espn_s2 = Sys.getenv("FF_ESPN_S2"),
  swid = Sys.getenv("FF_ESPN_SWID")
)


ff_rosters(conn_redraft)
#> Error: `col` must be a list-column

# this using dev branch, but same behavior on main -----
packageVersion("ffscrapr")
#> [1] '1.4.3.1'

Created on 2021-06-18 by the reprex package (v2.0.0)

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 4.0.4 (2021-02-15)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  ctype    English_United States.1252  
#>  tz       America/New_York            
#>  date     2021-06-18                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version  date       lib source        
#>  assertthat    0.2.1    2019-03-21 [1] CRAN (R 4.0.4)
#>  backports     1.2.1    2020-12-09 [1] CRAN (R 4.0.3)
#>  cachem        1.0.4    2021-02-13 [1] CRAN (R 4.0.4)
#>  checkmate     2.0.0    2020-02-06 [1] CRAN (R 4.0.4)
#>  cli           2.5.0    2021-04-26 [1] CRAN (R 4.0.5)
#>  crayon        1.4.1    2021-02-08 [1] CRAN (R 4.0.4)
#>  curl          4.3.1    2021-04-30 [1] CRAN (R 4.0.5)
#>  DBI           1.1.1    2021-01-15 [1] CRAN (R 4.0.4)
#>  digest        0.6.27   2020-10-24 [1] CRAN (R 4.0.4)
#>  dplyr         1.0.6    2021-05-05 [1] CRAN (R 4.0.5)
#>  ellipsis      0.3.2    2021-04-29 [1] CRAN (R 4.0.5)
#>  evaluate      0.14     2019-05-28 [1] CRAN (R 4.0.4)
#>  fansi         0.4.2    2021-01-15 [1] CRAN (R 4.0.4)
#>  fastmap       1.1.0    2021-01-25 [1] CRAN (R 4.0.4)
#>  ffscrapr    * 1.4.3.01 2021-06-18 [1] local         
#>  fs            1.5.0    2020-07-31 [1] CRAN (R 4.0.4)
#>  generics      0.1.0    2020-10-31 [1] CRAN (R 4.0.4)
#>  glue          1.4.2    2020-08-27 [1] CRAN (R 4.0.4)
#>  highr         0.9      2021-04-16 [1] CRAN (R 4.0.5)
#>  htmltools     0.5.1.1  2021-01-22 [1] CRAN (R 4.0.4)
#>  httr          1.4.2    2020-07-20 [1] CRAN (R 4.0.4)
#>  jsonlite      1.7.2    2020-12-09 [1] CRAN (R 4.0.4)
#>  knitr         1.33     2021-04-24 [1] CRAN (R 4.0.5)
#>  lifecycle     1.0.0    2021-02-15 [1] CRAN (R 4.0.4)
#>  lubridate     1.7.10   2021-02-26 [1] CRAN (R 4.0.4)
#>  magrittr      2.0.1    2020-11-17 [1] CRAN (R 4.0.4)
#>  memoise       2.0.0    2021-01-26 [1] CRAN (R 4.0.5)
#>  pillar        1.6.1    2021-05-16 [1] CRAN (R 4.0.5)
#>  pkgconfig     2.0.3    2019-09-22 [1] CRAN (R 4.0.4)
#>  ps            1.6.0    2021-02-28 [1] CRAN (R 4.0.4)
#>  purrr         0.3.4    2020-04-17 [1] CRAN (R 4.0.4)
#>  R6            2.5.0    2020-10-28 [1] CRAN (R 4.0.5)
#>  ratelimitr    0.4.1    2018-10-07 [1] CRAN (R 4.0.5)
#>  Rcpp          1.0.6    2021-01-15 [1] CRAN (R 4.0.4)
#>  reprex        2.0.0    2021-04-02 [1] CRAN (R 4.0.5)
#>  rlang         0.4.10   2020-12-30 [1] CRAN (R 4.0.4)
#>  rmarkdown     2.9      2021-06-15 [1] CRAN (R 4.0.4)
#>  rstudioapi    0.13     2020-11-12 [1] CRAN (R 4.0.4)
#>  sessioninfo   1.1.1    2018-11-05 [1] CRAN (R 4.0.5)
#>  stringi       1.5.3    2020-09-09 [1] CRAN (R 4.0.3)
#>  stringr       1.4.0    2019-02-10 [1] CRAN (R 4.0.4)
#>  styler        1.4.1    2021-03-30 [1] CRAN (R 4.0.5)
#>  tibble        3.1.2    2021-05-16 [1] CRAN (R 4.0.5)
#>  tidyr         1.1.3    2021-03-03 [1] CRAN (R 4.0.5)
#>  tidyselect    1.1.1    2021-04-30 [1] CRAN (R 4.0.5)
#>  utf8          1.2.1    2021-03-12 [1] CRAN (R 4.0.4)
#>  vctrs         0.3.8    2021-04-29 [1] CRAN (R 4.0.5)
#>  withr         2.4.2    2021-04-18 [1] CRAN (R 4.0.5)
#>  xfun          0.23     2021-05-15 [1] CRAN (R 4.0.5)
#>  yaml          2.2.1    2020-02-01 [1] CRAN (R 4.0.3)
#> 
#> [1] C:/Users/pij/Documents/R/win-library/4.0
#> [2] C:/Program Files/R/R-4.0.4/library

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions