Skip to content

Commit

Permalink
v1.4.8.04 - update ff_scoring to work with newest dplyr, resolves #402
Browse files Browse the repository at this point in the history
  • Loading branch information
tanho63 committed Jul 28, 2023
1 parent e2e4ae4 commit b2dc63a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: ffscrapr
Title: API Client for Fantasy Football League Platforms
Version: 1.4.8.03
Version: 1.4.8.04
Authors@R:
c(person(given = "Tan",
family = "Ho",
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ should be more robust (#397, thank you @logan-888!) (v1.4.8.02)
- `ff_startpositions.sleeper_conn()` now properly handles leagues with flex
positions that did not have dedicated posititions (#400, thank you @mcarman8!)
(v1.4.8.03)
- `ff_scoring.mfl_conn()` now works better with new dplyr versions (#402) (v1.4.8.04)

# ffscrapr 1.4.8

Expand Down
22 changes: 14 additions & 8 deletions R/mfl_scoring.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,27 @@ ff_scoring.mfl_conn <- function(conn) {
df <- df %>%
tibble::tibble() %>%
tidyr::unnest_wider(1)
} else if (!is.null(df$positions)) {
df <- df %>%
tibble::as_tibble()
}

if (!is.null(df$positions)) {
df <- df %>% tibble::as_tibble()
# convert each nested list of rules to tibble by bind_rows
# so that it can be unnested nicely
# see ffscrapr#344 for history
parse_rule <- function(rule){
vec_depth <- purrr::vec_depth(rule)
if(vec_depth == 3) rule <- tibble::as_tibble(rule)
if(vec_depth == 4) rule <- dplyr::bind_rows(rule)
rule %>%
dplyr::mutate_all(~unlist(.x) %>% unname())
}


df <- df %>%
dplyr::mutate(
# convert each nested list of rules to tibble by bind_rows
# so that it can be unnested nicely
# see ffscrapr#344 for history
rule = purrr::map(.data$rule, dplyr::bind_rows)
rule = purrr::map(.data$rule, parse_rule),
) %>%
tidyr::unnest("rule") %>%
tidyr::unnest_wider("rule") %>%
tidyr::unnest(c("points", "event", "range")) %>%
tidyr::separate_rows("positions", sep = "\\|") %>%
dplyr::left_join(mfl_allrules(conn), by = c("event" = "abbrev")) %>%
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-ff_scoring.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ test_that("ff_scoring returns a tibble", {

dlf <- mfl_connect(2019, 37920)
dlf_scoring <- ff_scoring(dlf)
wade <- mfl_connect(2023, 65804)
wade_scoring <- ff_scoring(wade)

jml_conn <- sleeper_connect(league_id = "522458773317046272", season = 2020)
jml_scoring <- ff_scoring(jml_conn)
Expand All @@ -17,6 +19,7 @@ test_that("ff_scoring returns a tibble", {
expect_tibble(jml_scoring, min.rows = 10)
expect_tibble(joe_scoring, min.rows = 10)
expect_tibble(tony_scoring, min.rows = 10)
expect_tibble(wade_scoring, min.rows = 10)
})

test_that("ff_scoring for templates return tibbles", {
Expand Down

0 comments on commit b2dc63a

Please sign in to comment.