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

Better handling for NaN in betting lines #96

Merged
merged 5 commits into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion R/cfbd_betting.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#' @importFrom purrr map_if
#' @importFrom dplyr filter as_tibble rename
#' @importFrom tidyr unnest
#' @importFrom stringr str_replace_all
#' @export
#' @examples
#' \donttest{
Expand Down Expand Up @@ -136,10 +137,27 @@ cfbd_betting_lines <- function(game_id = NULL,
# Get the content and return it as data.frame
df <- res %>%
httr::content(as = "text", encoding = "UTF-8") %>%
stringr::str_replace_all("NaN", 'null') %>%
jsonlite::fromJSON(flatten = TRUE) %>%
purrr::map_if(is.data.frame, list) %>%
dplyr::as_tibble() %>%
tidyr::unnest("lines")
tidyr::unnest("lines") %>%
dplyr::mutate(
saiemgilani marked this conversation as resolved.
Show resolved Hide resolved
overUnder = dplyr::case_when(
.data$overUnder == "null" ~ NA_character_,
.default = .data$overUnder
),
spread = dplyr::case_when(
.data$spread == "null" ~ NA_character_,
.default = .data$spread
),
formattedSpread = dplyr::case_when(
is.na(.data$spread) ~ NA_character_,
.default = .data$formattedSpread
)
)


akeaswaran marked this conversation as resolved.
Show resolved Hide resolved

if (!is.null(line_provider)) {
if (is.list(df) & length(df) == 0) {
Expand Down
Loading