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

Fix duplicate player hrefs in FBref functions #332

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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.4.0007
Version: 0.6.4.0008
Authors@R: c(
person("Jason", "Zivkovic", , "[email protected]", role = c("aut", "cre", "cph")),
person("Tony", "ElHabr", , "[email protected]", role = "ctb"),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* `fb_league_stats()` failing for `playing_time`. (0.6.4.0001) [#314](https://github.com/JaseZiv/worldfootballR/issues/314)
* `fb_advanced_match_stats()` throwing errors when there were no stat tables available for matches (0.6.4.0002) [#315](https://github.com/JaseZiv/worldfootballR/issues/315)
* `fb_player_match_logs()` failing for players who have played on multiple teams/leagues in the same season (0.6.4.0006) [#327](https://github.com/JaseZiv/worldfootballR/issues/327)
* `fb_league_stats(team_or_player = "player")` returning duplicate player hrefs (0.6.4.0008) [#331](https://github.com/JaseZiv/worldfootballR/issues/331)

### 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)
Expand Down
2 changes: 1 addition & 1 deletion R/fb_league_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
return(tibble::tibble())
}
renamed_table <- .rename_fb_cols(tables[[3]])
renamed_table[renamed_table$Rk != "Rk", ]
Copy link
Collaborator Author

@tonyelhabr tonyelhabr Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive by fix... this should have been assigned back to renamed_table 😅

renamed_table <- renamed_table[renamed_table$Rk != "Rk", ]
renamed_table <- .add_player_href(
renamed_table,
parent_element = elements[[3]],
Expand Down
7 changes: 2 additions & 5 deletions R/get_advanced_match_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
#' @importFrom stats setNames
.add_player_href <- function(df, parent_element, player_xpath) {
player_elements <- xml2::xml_find_all(parent_element, player_xpath)
players <- stats::setNames(
xml2::xml_attr(player_elements, "href"),
xml2::xml_text(player_elements)
)
player_hrefs <- xml2::xml_attr(player_elements, "href")
res <- dplyr::mutate(
df,
"Player_Href" = players[df$Player],
"Player_Href" = player_hrefs,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this assumes the number of player links will be equal to the number of rows in df. this is probably a fine assumption

.after = "Player"
)
return(res)
Expand Down
Loading