Skip to content

Commit

Permalink
use read_worldfootballr
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyelhabr committed Dec 28, 2024
1 parent 585876f commit c5913ee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/fb_advanced_match_stats/update_fb_advanced_match_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ update_fb_advanced_match_stats <- function(
season_end_year = latest_season
)

existing_data <- read_worldfootballr_rds(
existing_data <- read_worldfootballr(
name = name,
tag = fb_advanced_match_stats_tag
)
Expand Down
22 changes: 22 additions & 0 deletions R/piggyback.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,25 @@ read_worldfootballr_rds <- function(name, tag) {
path <- sprintf("https://github.com/%s/releases/download/%s/%s.rds", worldfootballr_repo, tag, name)
readRDS(url(path))
}

read_worldfootballr_csv <- function(name, tag) {
path <- sprintf("https://github.com/%s/releases/download/%s/%s.csv", worldfootballr_repo, tag, name)
read.csv(path)
}

safely_read_worldfootballr_rds <- purrr::safely(read_worldfootballr_rds)

read_worldfootballr <- function(name, tag) {
res <- safely_read_worldfootballr_rds(name, tag)
if (is.null(res$error)) {
return(res$value)
}
message(
sprintf(
'Missing RDS file at `name = "%s"` (`tag: "%s"`).\nTrying to read from the CSV.',
name,
tag
)
)
read_worldfootballr_csv(name, tag)
}

0 comments on commit c5913ee

Please sign in to comment.