R/getmatches.R

Defines functions get.matches

Documented in get.matches

get.matches <- function(username, password, season_id, competition_id, version = "v6",
                        baseurl = "https://data.statsbomb.com/api/",
                        remove.deleted.matches = TRUE){
  competition_id <- competition_id
  season_id <- season_id
  matches.url <- paste0(baseurl, version, "/competitions/", competition_id,
                        "/seasons/", season_id, "/matches")
  raw.match.api <- GET(url = matches.url, authenticate(username, password))
  matches.string <- rawToChar(raw.match.api$content)
  Encoding(matches.string) <- "UTF-8"
  matches <- fromJSON(matches.string, flatten = T)
  matches <- as_tibble(matches)
  if(remove.deleted.matches == TRUE){
    matches <- matches %>%
      filter(!match_status %in% c("deleted"))
  }
  return(matches)
}
statsbomb/StatsBombR documentation built on Dec. 3, 2024, 11:53 p.m.