add_stats <- function(gs, ...) {
gs$stats <- map(seq_len(nrow(gs)), \(i) game_stats(gs[i,], ...))
gs
}
game_stats <- function(g, team, stats_file, calculations, roles, key=BaseballScorecard::codes) {
stopifnot(is_tibble(g) & nrow(g)==1)
teams <- g |> select(code, game) |> unnest(game) |> pull(Team)
stopifnot(team %in% teams)
vs <- setdiff(teams, team)
header <- sprintf("%s, %s", paste(teams, collapse=" @ "), MDY_format(g$when))
if(!is.null(g$scorecard_link)) {
link <- g$scorecard_link
names(link) <- "LINK TO SCORECARD"
class(link) <- "hyperlink"
header <- list(header, link)
}
out <- make_stats_from_file(g, header, stats_file, calculations, roles, team, vs, key)
out
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.