-
Notifications
You must be signed in to change notification settings - Fork 62
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
add fb_team_match_stats and understat_available_teams functions #320
Conversation
@@ -271,6 +271,54 @@ tm_team_staff_urls <- function(team_urls, staff_role) { | |||
} | |||
|
|||
|
|||
#' Get Understat available teams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would this function scale across seasons? Hard coding team names means every season this would need to be re-done?
I don't love this function tbh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand you. I found an option how to do this without hard coding.
understat_available_teams <- function(leagues){
correct_leagues <- c("EPL", "La liga", "Bundesliga", "Serie A", "Ligue 1", "RFPL")
teams_list <- list()
for(lg in leagues){
if(!lg %in% correct_leagues){warning(glue::glue("League {lg} not found. Please check understats.com for the correct league name")); next}
match_url <- switch (lg,
'EPL' = 'https://understat.com/team/Arsenal',
'La liga' = 'https://understat.com/team/Barcelona',
'Bundesliga' = 'https://understat.com/team/Bayern_Munich',
'Serie A' = 'https://understat.com/team/AC_Milan',
'Ligue 1' = 'https://understat.com/team/Paris_Saint_Germain',
'RFPL' = 'https://understat.com/team/Spartak_Moscow'
)
team_page <- tryCatch(.load_page(match_url), error = function(e) NA)
teams_list[[lg]] <- team_page %>% rvest::html_nodes(".header-wrapper") %>% html_text() %>% gsub("([\n\t])|(\\d{4}/\\d{4})", "", .) %>% gsub('(?<!\\s)([[:upper:]])', '(&&)\\1', ., perl = TRUE) %>%
strsplit(., "\\(&&\\)", perl = TRUE) %>% unlist(.) %>% .[2:length(.)] %>% unlist(.)
}
if(length(leagues) == 1){
return(unlist(teams_list, use.names = FALSE))
}
return(teams_list)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been thinking about this for the last few days... I just think it feels a little out of place in worldfootballR, but happy to keep it in place for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks pretty good overall. in the future, i would love to see this for this to be split across 2 PRs (1 for each new function). no need to change this PR.
two requests:
- can you add usage to the vignettes?
- can you add tests?
…on_end_years input 2021:2022
…ozonaro/worldfootballR into fix-no-dom-league-stats
Fix for fb_league_stats() regarding non-dom-leagues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bumped the package version and added an entry to the news file to get this past the finish line 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@JaseZiv hello.
I create two functions for package:
fb_team_match_stats - return main team stats in match.
understat_available_teams - return all available teams names for selected league. Helper function, the results of which can be passed to function understat_team_meta