knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
This package is designed to collect baseball data from the web. Currently the package supports pulling data from the following sites:
https://www.baseball-reference.com/
To install the latest version use the following code:
devtools::install_github("nickpaul7/npmlb")
library(tidyverse)
To get all player game logs for entire season, use the code below.
path <- "/data/" npmlb::save_mlb_year(2019, save_path = path)
The scrape_team_full_roster()
function will collect the pitching and batting roster for a given team.
team <- "NYY" year <- "2019" df_roster <- npmlb::scrape_team_full_roster(team, year)
To extract the rosters, you can use the following code.
df_roster %>% filter(data_type == "pitching") %>% unnest()
The team_pages
data object contains the abbreviations for each team.
npmlb::team_pages
link <- "https://www.baseball-reference.com/players/gl.fcgi?id=lemahdj01&t=b&year=2019" type = "b" df_player_log <- npmlb::scrape_player_game_logs(link, type) dplyr::glimpse(df_player_log)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.