From b49e80ae640558e8434e0f4692e934cf41430369 Mon Sep 17 00:00:00 2001 From: Dan Morse Date: Sun, 12 Nov 2023 22:43:25 -0800 Subject: [PATCH] updated example tests and hockeyref player scraper --- R/get_game_shifts.R | 6 ++++-- R/get_player_stats_hr.R | 15 +++++++++++---- R/scrape_game.R | 6 ++++-- man/get_game_ids.Rd | 4 +++- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/R/get_game_shifts.R b/R/get_game_shifts.R index bf25e81..7b4012c 100644 --- a/R/get_game_shifts.R +++ b/R/get_game_shifts.R @@ -11,8 +11,10 @@ #' @export #' #' @examples -#' \dontrun{ -#' get_game_shifts(2020020561) +#' \donttest{ +#' try({ +#' get_game_shifts(game_id = 2023020201) +#' }) #' } get_game_shifts <- function(game_id){ diff --git a/R/get_player_stats_hr.R b/R/get_player_stats_hr.R index 664ce72..5320aec 100644 --- a/R/get_player_stats_hr.R +++ b/R/get_player_stats_hr.R @@ -11,9 +11,10 @@ #' @export #' #' @examples -#' \dontrun{ -#' #' get_player_stats("Wayne Gretzky") -#' get_player_stats_hr(c("Wayne Gretzky","Mario Lemieux")) +#' \donttest{ +#' try({ +#' get_player_stats_hr("Connor Bedard") +#' }) #' } get_player_stats_hr <- function(player_name, season = "career", league = "NHL"){ @@ -46,7 +47,13 @@ get_player_stats_hr <- function(player_name, season = "career", league = "NHL"){ } player <- session %>% - rvest::html_element("table") + rvest::html_element("#stats_basic_plus_nhl") + + # check for missing table + if(length(player) == 0){ + player <- session %>% + rvest::html_element("#stats_basic_nhl") + } # skip players with no stats # likely linking to wrong player diff --git a/R/scrape_game.R b/R/scrape_game.R index c864c80..e21c218 100644 --- a/R/scrape_game.R +++ b/R/scrape_game.R @@ -115,8 +115,10 @@ #' @export #' #' @examples -#' \dontrun{ -#' pbp <- scrape_game(2020020420) +#' \donttest{ +#' try({ +#' pbp <- scrape_game(game_id = 2023020201) +#' }) #' } scrape_game <- function(game_id){ diff --git a/man/get_game_ids.Rd b/man/get_game_ids.Rd index 90417dc..6fcd53f 100644 --- a/man/get_game_ids.Rd +++ b/man/get_game_ids.Rd @@ -30,8 +30,10 @@ A tibble containing game IDs and basic info for specified time frame Fetch game IDs for a single day or a full season } \examples{ -\dontrun{ +\donttest{ +try({ get_game_ids(season = 2020) get_game_ids(day = "2015-03-12") +}) } }