jthomasmock / espnscrapeR

Scrapes Or Collects NFL Data From ESPN
https://jthomasmock.github.io/espnscrapeR/
Other
51 stars 10 forks source link

List of Player ID's #17

Open jenn12138 opened 2 years ago

jenn12138 commented 2 years ago

Hi! Is there a way to get a list of player ID's from a season or multiple seasons? (i.e. all player IDs) I would like to use get_athlete() to get player info for all athletes from a season. Thank you!

jthomasmock commented 2 years ago

Howdy @jenn12138 !

To get athletes from multiple seasons you may want to use get_depth_chart() on your team of interest. That will return the player_id for your specific team of interest. You could then use purrr to iterate across the player IDs to get all of their individual data.

something like:

library(tidyverse)
library(espnscrapeR)
pit_roster <- purrr::map_dfr(2016:2021, ~get_depth_chart(.x, "PIT"))

pit_player_ids <- pit_roster %>%
  distinct(athlete_id) %>%
  pull()

pit_athletes <- pit_player_ids %>%
  purrr::map_dfr(get_athlete)