Skip to content

Commit

Permalink
fix these fucking tidyverse warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tanho63 committed Aug 13, 2023
1 parent fffb664 commit c111c95
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 112 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.07
Version: 1.4.8.09
Authors@R:
c(person(given = "Tan",
family = "Ho",
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ respect `season` in connection object (v1.4.8.06) (#408, thank you @RandalMorris
- `ff_rosters()` fleaflicker method now accepts `week` argument (v1.4.8.06)
- `ff_starters()` fleaflicker method expands to show injury data from box score
and keep NA data where a player is not in a slot. (v1.4.8.07)
- Silence a whack of tidyverse crap warnings (v1.4.8.09)


# ffscrapr 1.4.8

Expand Down
15 changes: 12 additions & 3 deletions R/espn_scoringhistory.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ ff_scoringhistory.espn_conn <- function(conn, season = 1999:nflreadr::most_recen
ff_scoring(conn) %>%
dplyr::left_join(
ffscrapr::nflfastr_stat_mapping %>% dplyr::filter(.data$platform == "espn"),
by = c("stat_name" = "ff_event")
by = c("stat_name" = "ff_event"),
relationship = "many-to-many"
)

ros <- .nflfastr_roster(season)
Expand All @@ -42,8 +43,16 @@ ff_scoringhistory.espn_conn <- function(conn, season = 1999:nflreadr::most_recen
}

ros %>%
dplyr::inner_join(ps, by = c("gsis_id"="player_id","season")) %>%
dplyr::inner_join(league_rules, by = c("metric"="nflfastr_event","pos")) %>%
dplyr::inner_join(
ps,
by = c("gsis_id"="player_id","season"),
relationship = "many-to-many"
) %>%
dplyr::inner_join(
league_rules,
by = c("metric"="nflfastr_event","pos"),
relationship = "many-to-many"
) %>%
dplyr::mutate(points = .data$value * .data$points) %>%
dplyr::group_by(.data$season, .data$week, .data$gsis_id, .data$sportradar_id) %>%
dplyr::mutate(points = round(sum(.data$points, na.rm = TRUE), 2)) %>%
Expand Down
8 changes: 4 additions & 4 deletions R/espn_standings.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ ff_standings.espn_conn <- function(conn, ...) {

records <-
standings_init %>%
dplyr::select(.data$record) %>%
dplyr::select("record") %>%
tidyr::hoist(
"record",
"overall"
) %>%
dplyr::select(-.data$record) %>%
dplyr::select(-"record") %>%
tidyr::hoist(
"overall",
"h2h_wins" = "wins",
Expand All @@ -55,7 +55,7 @@ ff_standings.espn_conn <- function(conn, ...) {
"points_for" = "pointsFor",
"points_against" = "pointsAgainst",
) %>%
dplyr::select(-.data$overall)
dplyr::select(-"overall")

allplay <- ff_schedule(conn) %>%
.add_allplay()
Expand All @@ -65,7 +65,7 @@ ff_standings.espn_conn <- function(conn, ...) {

standings <-
dplyr::bind_cols(
standings_init %>% dplyr::select(-.data$record),
standings_init %>% dplyr::select(-"record"),
records
) %>%
dplyr::left_join(allplay, by = c("franchise_id")) %>%
Expand Down
7 changes: 6 additions & 1 deletion R/flea_schedule.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ ff_schedule.flea_conn <- function(conn, week = 1:17, ...) {
)),
dplyr::starts_with("is")
) %>%
dplyr::mutate(dplyr::across(dplyr::contains("_score"), purrr::map_dbl, ~ replace(.x, is.null(.x), NA)))
dplyr::mutate(
dplyr::across(
dplyr::contains("_score"),
function(col) purrr::map_dbl(col, ~ replace(.x, is.null(.x), NA))
)
)

return(schedule)
}
13 changes: 10 additions & 3 deletions R/flea_scoringhistory.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ ff_scoringhistory.flea_conn <- function(conn, season = 1999:nflreadr::most_recen
ffscrapr::nflfastr_stat_mapping %>%
dplyr::filter(.data$platform == "fleaflicker") %>%
dplyr::mutate(ff_event = as.integer(.data$ff_event)),
by = c("event_id" = "ff_event")
by = c("event_id" = "ff_event"),
relationship = "many-to-many"
)
ros <- .nflfastr_roster(season)

Expand All @@ -40,8 +41,14 @@ ff_scoringhistory.flea_conn <- function(conn, season = 1999:nflreadr::most_recen
}

ros %>%
dplyr::inner_join(ps, by = c("gsis_id"="player_id","season")) %>%
dplyr::inner_join(league_rules, by = c("metric"="nflfastr_event","pos")) %>%
dplyr::inner_join(
ps,
by = c("gsis_id"="player_id","season"),
relationship = "many-to-many") %>%
dplyr::inner_join(
league_rules,
by = c("metric"="nflfastr_event","pos"),
relationship = "many-to-many") %>%
dplyr::mutate(points = .data$value * .data$points) %>%
dplyr::group_by(.data$season, .data$week, .data$gsis_id, .data$sportradar_id) %>%
dplyr::mutate(points = round(sum(.data$points, na.rm = TRUE), 2)) %>%
Expand Down
17 changes: 12 additions & 5 deletions R/flea_standings.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#'
#' @export
ff_standings.flea_conn <- function(conn, include_allplay = TRUE, include_potentialpoints = TRUE, ...) {
standings <- fleaflicker_getendpoint("FetchLeagueStandings",
standings <- fleaflicker_getendpoint(
"FetchLeagueStandings",
league_id = conn$league_id,
season = conn$season,
sport = "NFL"
Expand All @@ -36,10 +37,15 @@ ff_standings.flea_conn <- function(conn, include_allplay = TRUE, include_potenti
"points_for" = "pointsFor",
"points_against" = "pointsAgainst"
) %>%
dplyr::mutate(dplyr::across(c("points_for", "points_against"), purrr::map_dbl, purrr::pluck, "value")) %>%
dplyr::mutate(
dplyr::across(
c("points_for", "points_against"),
function(col) purrr::map_dbl(col, purrr::pluck, "value")
)
)%>%
tidyr::hoist("recordOverall", "h2h_wins" = "wins", "h2h_losses" = "losses", "h2h_ties" = "ties") %>%
dplyr::mutate(
dplyr::across(dplyr::starts_with("h2h"), tidyr::replace_na, 0),
dplyr::across(dplyr::starts_with("h2h"), ~tidyr::replace_na(.x,0)),
h2h_winpct = (.data$h2h_wins / (.data$h2h_wins + .data$h2h_losses + .data$h2h_ties)) %>% round(3)
) %>%
dplyr::select(
Expand Down Expand Up @@ -74,14 +80,15 @@ ff_standings.flea_conn <- function(conn, include_allplay = TRUE, include_potenti
dplyr::filter(!is.na(.data$result)) %>%
dplyr::distinct(.data$week, .data$game_id) %>%
dplyr::mutate(potentialpoints = purrr::map2(.data$week, .data$game_id, .flea_potentialpointsweek, conn)) %>%
tidyr::unnest(.data$potentialpoints) %>%
tidyr::unnest("potentialpoints") %>%
dplyr::group_by(.data$franchise_id) %>%
dplyr::summarise(potential_points = sum(.data$potential_points)) %>%
dplyr::ungroup()
}

.flea_potentialpointsweek <- function(week, game_id, conn) {
x <- fleaflicker_getendpoint("FetchLeagueBoxscore",
x <- fleaflicker_getendpoint(
"FetchLeagueBoxscore",
sport = "NFL",
scoring_period = week,
fantasy_game_id = game_id,
Expand Down
Loading

0 comments on commit c111c95

Please sign in to comment.