Skip to content

Commit

Permalink
Merge pull request #397 from drasbaek/main
Browse files Browse the repository at this point in the history
Enhancement suggestion: Add date of birth to `tm_expiring_contracts`
  • Loading branch information
tonyelhabr authored Sep 23, 2024
2 parents e1093e0 + b7c8b61 commit dc489be
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
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

0 comments on commit dc489be

Please sign in to comment.