knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)

Introduction

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/

Install

To install the latest version use the following code:

devtools::install_github("nickpaul7/npmlb")

Required Packages

library(tidyverse)

Player Game Logs

To get all player game logs for entire season, use the code below.

path <- "/data/"
npmlb::save_mlb_year(2019, save_path = path)

Get Team Roster

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

Scrape a Player Page

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)


nickpaul7/npmlb documentation built on Nov. 4, 2019, 10:04 p.m.