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

Enhancement suggestion: Add date of birth to tm_expiring_contracts #397

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: worldfootballR
Title: Extract and Clean World Football (Soccer) Data
Version: 0.6.6.0000
Version: 0.6.6.0001
Authors@R: c(
person("Jason", "Zivkovic", , "[email protected]", role = c("aut", "cre", "cph")),
person("Tony", "ElHabr", , "[email protected]", role = "ctb"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Improvements

* `tm_expiring_contracts()` returns additional `date_of_birth` column. (0.6.6.0001) [#355](https://github.com/JaseZiv/worldfootballR/issues/397)

***

# worldfootballR 0.6.6
Expand Down
5 changes: 4 additions & 1 deletion R/tm_expiring_contracts.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ tm_expiring_contracts <- function(country_name, contract_end_year, league_url =
error = function(e) player_name <- NA_character_)
player_url <- tryCatch(exp_pg %>% rvest::html_nodes(".inline-table .hauptlink a") %>% rvest::html_attr("href") %>% paste0(main_url, .),
error = function(e) player_url <- NA_character_)
date_of_birth <- tryCatch(exp_pg %>% rvest::html_nodes("td.zentriert:nth-child(2)") %>%
rvest::html_text(), error = function(e) date_of_birth <- NA_character_)
position <- tryCatch(exp_pg %>% rvest::html_nodes(".inline-table tr+ tr td") %>% rvest::html_text(),
error = function(e) position <- NA_character_)
nationality <- tryCatch(exp_pg %>% rvest::html_nodes(".flaggenrahmen:nth-child(1)") %>% rvest::html_attr("title"),
Expand All @@ -107,7 +109,7 @@ tm_expiring_contracts <- function(country_name, contract_end_year, league_url =
agent <- tryCatch(exp_pg %>% rvest::html_nodes(".rechts+ .hauptlink") %>% rvest::html_text() %>% stringr::str_squish(),
error = function(e) agent <- NA_character_)

out_df <- cbind(player_name, player_url, position, nationality, second_nationality,
out_df <- cbind(player_name, player_url, date_of_birth, position, nationality, second_nationality,
current_club, contract_expiry, contract_option, player_market_value, transfer_fee, agent) %>% data.frame()

if(is.na(league_url)) {
Expand All @@ -120,6 +122,7 @@ tm_expiring_contracts <- function(country_name, contract_end_year, league_url =
out_df <- out_df %>%
dplyr::mutate(player_name = as.character(.data[["player_name"]]),
player_url = as.character(.data[["player_url"]]),
date_of_birth = as.character(.data[["date_of_birth"]]),
position = as.character(.data[["position"]]),
nationality = as.character(.data[["nationality"]]),
second_nationality = as.character(.data[["second_nationality"]]),
Expand Down
Loading