@@ -52,19 +52,24 @@ fetch_player_details <- function(team = NULL,
5252cli :: cli_inform(" Returning historical player details from source `{source}`" )
5353 }
5454
55- dat <- switch (source ,
56- " AFL" = purrr :: map_dfr(
57- season ,
58- ~ fetch_player_details_afl(
59- season = .x ,
60- team = team ,
61- comp = comp
62- )
63- ),
64- " afltables" = fetch_player_details_afltables(team ),
65- " footywire" = fetch_player_details_footywire(team ,current = current ),
66- NULL
67- )
55+ if (source == " AFL" & is.null(season )) {
56+ dat <- fetch_player_details_afl(team = team ,
57+ season = season ,
58+ comp = comp ,
59+ current = current )
60+ }else if (source == " AFL" ) {
61+ dat <- purrr :: map_dfr(season ,
62+ ~ fetch_player_details_afl(team = team ,
63+ season = .x ,
64+ current = current ,
65+ comp = comp ))
66+ }else if (source == " afltables" ) {
67+ dat <- fetch_player_details_afltables(team = team )
68+ }else if (source == " footywire" ) {
69+ dat <- fetch_player_details_footywire(team = team ,current = current )
70+ }else {
71+ dat <- NULL
72+ }
6873
6974if (is.null(dat ))cli :: cli_warn(" The source\" {source}\" does not have Player Details data. Please use one of\" afltables\" and\" footywire\" " )
7075return (dat )
@@ -88,12 +93,18 @@ fetch_player_details_afl <- function(season = NULL, team = NULL, current = TRUE,
8893# get season id
8994comp_seas_id <- find_season_id(season ,comp )
9095
96+ # If it's not current season, check previous season
97+ if (is.null(comp_seas_id )& current ) {
98+ comp_seas_id <- find_season_id(season - 1 ,comp )
99+ }
100+
101+ # If still not found, return null
91102if (is.null(comp_seas_id )) {
92103cli :: cli_warn(" No player details data found for season {season} on AFL.com.au for {comp}" )
93104return (NULL )
94105 }
95106
96- if (! comp %in% c(" AFLM" ," AFLW" ))official_teams <- TRUE
107+ if (! comp %in% c(" AFLM" ," AFLW" )| official_teams == TRUE )official_teams <- TRUE
97108
98109# return team abbreviation
99110if (! is.null(team )) {
@@ -114,6 +125,7 @@ fetch_player_details_afl <- function(season = NULL, team = NULL, current = TRUE,
114125team_names <- team_dat $ name
115126 }
116127
128+
117129args <- list (
118130teamId = team_ids ,
119131team = team_names ,