From 6f6711c9cbedf56fec7810ab43a3c5d2b3b49978 Mon Sep 17 00:00:00 2001 From: JaseZiv Date: Thu, 2 Nov 2023 12:46:06 +1100 Subject: [PATCH] address #336 and #338 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ R/player_market_values.R | 8 ++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7fe59512..058b0732 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: worldfootballR Title: Extract and Clean World Football (Soccer) Data -Version: 0.6.4.0009 +Version: 0.6.4.0010 Authors@R: c( person("Jason", "Zivkovic", , "jaseziv83@gmail.com", role = c("aut", "cre", "cph")), person("Tony", "ElHabr", , "anthonyelhabr@gmail.com", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index 6cc44c51..4553cbb0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,8 @@ * `fb_league_stats(team_or_player = "player")` returning duplicate player hrefs (0.6.4.0008) [#331](https://github.com/JaseZiv/worldfootballR/issues/331) worldfootballR/issues/327) * `fb_league_stats(team_or_player = "player")` returning wrong season's data for Australian league (0.6.4.0009) [#333](https://github.com/JaseZiv/worldfootballR/issues/333) +* `tm_player_market_values()` returing the player name and valuation on separate rows in the `player_name` column [#338] (https://github.com/JaseZiv/worldfootballR/issues/338) and also returning `NA`s for the `player_age` column [#336](https://github.com/JaseZiv/worldfootballR/issues/336) (0.6.4.0010) + ### Improvements * `fb_player_season_stats()` now includes the ability to get a player's national team stats [https://github.com/JaseZiv/worldfootballR/pull/310/files] (0.6.4.0002) diff --git a/R/player_market_values.R b/R/player_market_values.R index d3992e32..3fb6bb5a 100644 --- a/R/player_market_values.R +++ b/R/player_market_values.R @@ -107,12 +107,12 @@ tm_player_market_values <- function(country_name, start_year, league_url = NA) { player_num <- NA_character_ } # player names - player_name <- team_data %>% rvest::html_nodes(".hauptlink a") %>% rvest::html_text() %>% stringr::str_squish() + player_name <- team_data %>% rvest::html_nodes(".inline-table a") %>% rvest::html_text() %>% stringr::str_squish() if(length(player_name) == 0) { player_name <- NA_character_ } # player_url - player_url <- team_data %>% rvest::html_nodes(".hauptlink a") %>% rvest::html_attr("href") %>% + player_url <- team_data %>% rvest::html_nodes(".inline-table a") %>% rvest::html_attr("href") %>% paste0(main_url, .) if(length(player_url) == 0) { player_url <- NA_character_ @@ -220,12 +220,12 @@ tm_player_market_values <- function(country_name, start_year, league_url = NA) { dplyr::left_join(all_seasons_df, by = "season_urls") - all_seasons_df <- all_seasons_df %>% + aa <- all_seasons_df %>% dplyr::mutate(player_market_value_euro = mapply(.convert_value_to_numeric, player_market_value)) %>% dplyr::mutate(date_joined = .tm_fix_dates(.data[["date_joined"]]), contract_expiry = .tm_fix_dates(.data[["contract_expiry"]])) %>% tidyr::separate(., player_birthday, into = c("Month", "Day", "Year"), sep = " ", remove = F) %>% - dplyr::mutate(player_age = sub(".*(?:\\((.*)\\)).*|.*", "\\1", .data[["Year"]]), + dplyr::mutate(player_age = gsub(".*\\(", "", .data[["player_birthday"]]) %>% gsub("\\)", "", .), Day = gsub(",", "", .data[["Day"]]) %>% as.numeric(), Year = as.numeric(gsub("\\(.*", "", .data[["Year"]])), Month = match(.data[["Month"]], month.abb),