getRetrosheet: Import single-season retrosheet data as a structured R object

View source: R/getRetrosheet.R

getRetrosheetR Documentation

Import single-season retrosheet data as a structured R object

Description

This function downloads and parses data from https://www.retrosheet.org for the game-log, event, (play-by-play), roster, and schedule files.

Usage

getRetrosheet(
  type,
  year,
  team,
  schedSplit = NULL,
  stringsAsFactors = FALSE,
  cache = NA
)

Arguments

type

character. This argument can take on either of "game" for game-logs, "play" for play-by-play (a.k.a. event) data, "roster" for team rosters, or "schedule" for the game schedule for the given year.

year

integer. A valid four-digit year.

team

character. Only to be used if type = "play". A single valid team ID for the given year. For available team IDs for the given year call getTeamIDs(year). The available teams are in the "TeamID" column.

schedSplit

One of "Date", "HmTeam", or "TimeOfDay" to return a list split by the given value, or NULL (the default) for no splitting.

stringsAsFactors

logical. The stringsAsFactors argument as used in data.frame. Currently applicable to types "game" and "schedule".

cache

character. Path to local cache of retrosheet data. If file doesn't exist, files will be saved locally for future use. Defaults to "NA" so as not to save local data without explicit permission

Value

The following return values are possible for the given type

  • game - a data frame of gamelog data for the given year

  • play - a list, each element of which is a single game's play-by-play data for the given team and year. Each list element is also a list, containing the play-by-play data split into individual matrices.

  • roster - a named list, each element containing the roster for the named team for the given year, as a data frame.

  • schedule - a data frame containing the game schedule for the given year

Examples


## get the full 1995 season schedule
getRetrosheet("schedule", 1995)

## get the same schedule, split by time of day
getRetrosheet("schedule", 1995, schedSplit = "TimeOfDay")

## get the roster data for the 1995 season, listed by team
getRetrosheet("roster", 1995)

## get the full gamelog data for the 2012 season
getRetrosheet("game", 2012)

## get the play-by-play data for the San Francisco Giants' 2012 season
getRetrosheet("play", 2012, "SFN")



retrosheet documentation built on July 10, 2023, 2:02 a.m.