Skip to contents

Translate player IDs to player headshots and render these images in html tables with the 'gt' package. IDs are ESPN athlete IDs by default, or as id_system says. Only IDs that get no headshot URL (missing, malformed, or absent from the id map id_system reads, such as "gsis" or a provider's) are left as text. An ID that gets a URL keeps it even when the CDN has no photo for it, so that cell can show a broken image.

Usage

gt_sdv_headshots(
  gt_object,
  columns,
  league,
  height = 30,
  locations = NULL,
  id_system = "espn"
)

Arguments

gt_object

A table object created using gt::gt().

columns

The columns for which the image translation should be applied. Argument has no effect if locations is not NULL.

league

A league key from sdv_leagues().

height

The absolute height (px) of the image in the table cell.

locations

If NULL (the default), the function will render logos in argument columns. Otherwise, the cell or set of cells to be associated with the team name transformation. Only gt::cells_body(), gt::cells_stub(), gt::cells_column_labels(), and gt::cells_row_groups() helper functions can be used here.

id_system

"espn" (ESPN athlete ids; the default, for every league with ESPN headshots), "gsis" (nflverse's NFL gsis ids, such as "00-0033873", read through a published map), "league" (the league's own player id), or another provider's player id, drawn as the ESPN athlete's headshot: "fox", "yahoo", "cbs", "kenpom", "ncaa" (stats.ncaa.org), "nba_stats" or "wnba_stats". The details of sdv_headshot_url() list which leagues take which.

Value

An object of class gt_tbl.

Examples

# \donttest{
library(gt)
library(sdvplotR)

df <- data.frame(
  player_id = c("00-0033873", "00-0026498", "00-0035228"),
  player_name = c("P.Mahomes", "M.Stafford", "K.Murray")
)

df |>
  gt() |>
  gt_sdv_headshots(columns = "player_id", league = "nfl", id_system = "gsis")
player_id player_name
Player 00-0033873 headshot P.Mahomes
Player 00-0026498 headshot M.Stafford
Player 00-0035228 headshot K.Murray
# }