### Install cricketdata from CRAN Source: https://github.com/robjhyndman/cricketdata/blob/master/README.md Use the pak package to install the stable version of cricketdata from CRAN. ```r # install.packages("pak") pak::pak("cricketdata") ``` -------------------------------- ### Install cricketdata from GitHub Source: https://github.com/robjhyndman/cricketdata/blob/master/README.md Use the pak package to install the development version of cricketdata directly from the GitHub repository. ```r pak::pak("robjhyndman/cricketdata") ``` -------------------------------- ### Access Pre-loaded Player Metadata Source: https://context7.com/robjhyndman/cricketdata/llms.txt The player_meta dataset is pre-loaded and contains metadata for over 16,000 players for fast local lookups. ```r library(cricketdata) library(dplyr) ``` -------------------------------- ### Fetch Ball-by-Ball and Match Data with fetch_cricsheet Source: https://context7.com/robjhyndman/cricketdata/llms.txt Downloads detailed match metadata, player information, or ball-by-ball data from Cricsheet. Use cricsheet_codes to identify available competition identifiers. ```r library(cricketdata) library(dplyr) # View available competition codes cricsheet_codes #> # A tibble: 44 x 2 #> code competition #> #> 1 tests Test matches #> 2 odis One-Day Internationals #> 3 t20s T20 Internationals #> 4 ipl Indian Premier League #> 5 wbb Women's Big Bash League #> ... # Fetch WBBL ball-by-ball data wbbl_bbb <- fetch_cricsheet(competition = "wbbl", type = "bbb", gender = "female") # View ball-by-ball structure (T20 matches include enhanced columns) head(wbbl_bbb) #> # A tibble: 6 x 30 #> match_id season start_date venue innings over ball batting_team bowling_team #> #> 1 1234567 2023 2023-10-26 Sydney 1 1 1 Sixers Thunder #> ... # Fetch match metadata wbbl_matches <- fetch_cricsheet(competition = "wbbl", type = "match", gender = "female") # Fetch player information wbbl_players <- fetch_cricsheet(competition = "wbbl", type = "player", gender = "female") # Calculate batting statistics per season batting_per_season <- wbbl_bbb |> group_by(season, striker) |> summarise( innings_total = length(unique(match_id)), runs_off_bat_total = sum(runs_off_bat), balls_faced_total = length(ball), .groups = "drop" ) |> mutate( runs_per_innings_avg = round(runs_off_bat_total / innings_total, 1), strike_rate = round(runs_off_bat_total / balls_faced_total * 100, 1) ) |> filter(innings_total > 2) # Fetch IPL ball-by-ball data ipl_bbb <- fetch_cricsheet(competition = "ipl", type = "bbb", gender = "male") ``` -------------------------------- ### Retrieve Player Metadata with fetch_player_meta Source: https://context7.com/robjhyndman/cricketdata/llms.txt Downloads metadata for players using their Cricinfo IDs. For large-scale lookups, the pre-loaded player_meta dataset is more efficient. ```r library(cricketdata) # Fetch metadata for specific players aus_stars <- fetch_player_meta(c(329336, 275487)) # Meg Lanning, Ellyse Perry aus_stars #> # A tibble: 2 x 7 #> cricinfo_id name full_name country dob batting_style bowling_style #> #> 1 329336 Meg Lanning Meghann Lanning Australia 1992-03-25 Right-hand bat Right-arm leg break #> 2 275487 Ellyse Perry Ellyse Alexandra Australia 1990-11-03 Right-hand bat Right-arm medium fast # For bulk lookups, use the pre-loaded dataset instead (faster) head(player_meta) #> # A tibble: 6 x 11 #> cricinfo_id cricsheet_id unique_name full_name name country dob batting_style bowling_style ``` -------------------------------- ### Fetch Aggregate Cricket Statistics with fetch_cricinfo Source: https://context7.com/robjhyndman/cricketdata/llms.txt Retrieves career or innings-by-innings batting, bowling, or fielding statistics from ESPNCricinfo. Arguments are case-insensitive and support partial matching. ```r library(cricketdata) library(dplyr) library(ggplot2) # Fetch all Women's T20 bowling career statistics wt20_bowling <- fetch_cricinfo("T20", "Women", "Bowling") # View the data structure head(wt20_bowling) #> # A tibble: 6 x 15 #> Player Country Start End Matches Innings Overs Maidens Runs Wickets #> #> 1 EA Perry Aust 2008 2024 134 125 427 8 2841 115 #> ... # Fetch Australian men's ODI batting data by innings aus_odi_batting <- fetch_cricinfo("ODI", "Men", "Batting", type = "innings", country = "Australia") # Visualize runs over time aus_odi_batting |> ggplot(aes(x = Date, y = Runs)) + geom_point(alpha = 0.3, col = "#D55E00") + geom_smooth() + ggtitle("Australia Men ODI: Runs per Innings") # Fetch Indian test fielding career statistics india_fielding <- fetch_cricinfo("Test", "Men", "Fielding", country = "India") # Analyze wicketkeeper vs fielder dismissals india_fielding |> mutate(wktkeeper = (CaughtBehind > 0) | (Stumped > 0)) |> ggplot(aes(x = Matches, y = Dismissals, col = wktkeeper)) + geom_point() + ggtitle("Indian Men Test Fielding") ``` -------------------------------- ### fetch_player_meta - Fetch Player Metadata Source: https://context7.com/robjhyndman/cricketdata/llms.txt Downloads metadata for one or more players by their Cricinfo IDs. ```APIDOC ## fetch_player_meta - Fetch Player Metadata from ESPNCricinfo ### Description Downloads metadata (name, country, date of birth, batting/bowling styles) for one or more players by their Cricinfo IDs. Useful for enriching analysis with player attributes. For bulk lookups, consider using the pre-loaded `player_meta` dataset instead. ### Method GET ### Endpoint /fetch_player_meta ### Parameters #### Query Parameters - **player_ids** (numeric vector) - Required - A vector of ESPNCricinfo player IDs. ### Request Example ```r library(cricketdata) # Fetch metadata for specific players aus_stars <- fetch_player_meta(c(329336, 275487)) # Meg Lanning, Ellyse Perry print(aus_stars) ``` ### Response #### Success Response (200) - **cricinfo_id** (numeric) - The ESPNCricinfo ID of the player. - **name** (string) - The short name of the player. - **full_name** (string) - The full name of the player. - **country** (string) - The country the player represents. - **dob** (date) - The date of birth of the player. - **batting_style** (string) - The player's batting style. - **bowling_style** (string) - The player's bowling style. #### Response Example ```r # A tibble: 2 x 7 cricinfo_id name full_name country dob batting_style bowling_style 1 329336 Meg Lanning Meghann Lanning Australia 1992-03-25 Right-hand bat Right-arm leg break 2 275487 Ellyse Perry Ellyse Alexandra Australia 1990-11-03 Right-hand bat Right-arm medium fast ``` ``` -------------------------------- ### Update Player Metadata with update_player_meta Source: https://context7.com/robjhyndman/cricketdata/llms.txt Updates the local player_meta dataset with new information from ESPNCricinfo and Cricsheet. ```r library(cricketdata) # Update player metadata to current (incremental update) # This fetches only new players not in the existing player_meta new_player_meta <- update_player_meta() # Start fresh and download all player metadata (takes a long time) complete_player_meta <- update_player_meta(start_again = TRUE) # Check how many new players were added nrow(new_player_meta) - nrow(player_meta) ``` -------------------------------- ### Explore Player Metadata Source: https://context7.com/robjhyndman/cricketdata/llms.txt Functions to inspect, filter, and search the player_meta dataset for player information. ```r head(player_meta) ``` ```r player_meta |> filter(country == "India") |> head() ``` ```r player_meta |> filter(grepl("Kohli", full_name, ignore.case = TRUE)) ``` ```r player_meta |> filter(grepl("Left-hand", batting_style)) ``` -------------------------------- ### player_meta - Pre-loaded Player Metadata Dataset Source: https://context7.com/robjhyndman/cricketdata/llms.txt A pre-loaded tibble containing metadata for players who appear on both Cricsheet and ESPNCricinfo. ```APIDOC ## player_meta - Pre-loaded Player Metadata Dataset ### Description A pre-loaded tibble containing metadata for 16,101 players who appear on both Cricsheet and ESPNCricinfo (as of March 2025). Use this for fast lookups instead of making API calls. ### Method GET ### Endpoint /player_meta ### Parameters None ### Request Example ```r library(cricketdata) library(dplyr) # View the first few rows of the player_meta dataset head(player_meta) ``` ### Response #### Success Response (200) - **cricinfo_id** (numeric) - The ESPNCricinfo ID of the player. - **cricsheet_id** (string) - The Cricsheet ID of the player. - **unique_name** (string) - A unique identifier for the player. - **full_name** (string) - The full name of the player. - **name** (string) - The short name of the player. - **country** (string) - The country the player represents. - **dob** (date) - The date of birth of the player. - **batting_style** (string) - The player's batting style. - **bowling_style** (string) - The player's bowling style. #### Response Example ```r # A tibble: 6 x 11 cricinfo_id cricsheet_id unique_name name country dob batting_style bowling_style 1 275487 10000.1 ellyse_perry Ellyse A. Perry Australia 1990-11-03 Right-hand bat Right-arm medium fast 2 329336 10001.1 meg_lanning Meghann Lanning Australia 1992-03-25 Right-hand bat Right-arm leg break ... ``` ``` -------------------------------- ### Fetch Player Statistics with fetch_player_data Source: https://context7.com/robjhyndman/cricketdata/llms.txt Retrieves innings-by-innings statistics for a player using their Cricinfo ID. Requires the player ID obtained from find_player_id(). ```r library(cricketdata) library(dplyr) library(ggplot2) # Fetch Ellyse Perry's T20 batting data ellyse_perry <- fetch_player_data(275487, "T20", "batting") head(ellyse_perry) #> # A tibble: 6 x 12 #> Date Innings Opposition Ground Runs BF SR Pos Dismissal 4s 6s #> # Plot batting performance over time ellyse_perry |> filter(!is.na(Runs)) |> ggplot(aes(x = Date, y = Runs, col = Dismissal)) + geom_point() + ggtitle("Ellyse Perry's T20 Scores") # Fetch Rahul Dravid's ODI fielding data rahul_dravid <- fetch_player_data(28114, "ODI", "fielding") # Fetch Lasith Malinga's Test bowling data lasith_malinga <- fetch_player_data(49758, "Test", "bowling") # Complete workflow: find player and fetch data meg_id <- find_player_id("Meg Lanning")$ID[1] meg_odi <- fetch_player_data(meg_id, "ODI", "batting") |> mutate( NotOut = (Dismissal == "not out"), NotOut = tidyr::replace_na(NotOut, FALSE) ) # Calculate batting average meg_average <- meg_odi |> summarise( Innings = sum(!is.na(Runs)), Average = sum(Runs, na.rm = TRUE) / (Innings - sum(NotOut)) ) |> pull(Average) # Visualize ODI career ggplot(meg_odi) + geom_hline(aes(yintercept = meg_average), col = "gray") + geom_point(aes(x = Date, y = Runs, col = NotOut)) + ggtitle(paste("Meg Lanning ODI Scores - Average:", round(meg_average, 2))) ``` -------------------------------- ### fetch_player_data - Fetch Individual Player Statistics Source: https://context7.com/robjhyndman/cricketdata/llms.txt Retrieves innings-by-innings statistics for a specific player from ESPNCricinfo, requiring the player's Cricinfo ID. ```APIDOC ## fetch_player_data - Fetch Individual Player Match-by-Match Statistics ### Description Retrieves innings-by-innings statistics for a specific player from ESPNCricinfo. Requires the player's Cricinfo ID (obtainable via `find_player_id()`). Returns one row per innings played in the specified format. ### Method GET ### Endpoint /fetch_player_data ### Parameters #### Path Parameters - **player_id** (numeric) - Required - The ESPNCricinfo ID of the player. - **format** (string) - Required - The format of the data to fetch (e.g., "T20", "ODI", "Test"). - **type** (string) - Required - The type of statistics to fetch (e.g., "batting", "bowling", "fielding"). ### Request Example ```r library(cricketdata) library(dplyr) library(ggplot2) # Fetch Ellyse Perry's T20 batting data ellyse_perry <- fetch_player_data(275487, "T20", "batting") print(head(ellyse_perry)) # Fetch Rahul Dravid's ODI fielding data rahul_dravid <- fetch_player_data(28114, "ODI", "fielding") print(rahul_dravid) # Fetch Lasith Malinga's Test bowling data lasith_malinga <- fetch_player_data(49758, "Test", "bowling") print(lasith_malinga) ``` ### Response #### Success Response (200) - **Date** (date) - The date of the match. - **Innings** (numeric) - The innings number. - **Opposition** (string) - The opposing team. - **Ground** (string) - The venue of the match. - **Runs** (numeric) - Runs scored. - **BF** (numeric) - Balls faced. - **SR** (numeric) - Strike rate. - **Pos** (string) - Batting position. - **Dismissal** (string) - How the player was dismissed. - **4s** (numeric) - Number of fours hit. - **6s** (numeric) - Number of sixes hit. #### Response Example ```r # A tibble: 6 x 12 Date Innings Opposition Ground Runs BF SR Pos Dismissal 4s 6s 1 2007-03-08 1 India Melbourne 21 37 56.8 7 c "" 2 0 2 2007-03-11 1 Sri Lanka Hobart 12 27 44.4 7 c "" 0 0 ... ``` ``` -------------------------------- ### update_player_meta - Update Player Metadata Database Source: https://context7.com/robjhyndman/cricketdata/llms.txt Updates the `player_meta` dataset with the latest player information from ESPNCricinfo and Cricsheet. ```APIDOC ## update_player_meta - Update the Player Metadata Database ### Description Updates the `player_meta` dataset with the latest player information from ESPNCricinfo and Cricsheet. Use this to get metadata for newly registered players not in the shipped dataset. ### Method POST ### Endpoint /update_player_meta ### Parameters #### Query Parameters - **start_again** (boolean) - Optional - If TRUE, downloads all player metadata from scratch. Defaults to FALSE (incremental update). ### Request Example ```r library(cricketdata) # Update player metadata to current (incremental update) new_player_meta <- update_player_meta() # Start fresh and download all player metadata (takes a long time) complete_player_meta <- update_player_meta(start_again = TRUE) ``` ### Response #### Success Response (200) - **player_meta** (tibble) - The updated player metadata dataset. #### Response Example ```r # A tibble: 16101 x 11 cricinfo_id cricsheet_id unique_name full_name name country dob batting_style bowling_style 1 275487 10000.1 ellyse_perry Ellyse A. Perry Australia 1990-11-03 Right-hand bat Right-arm medium fast 2 329336 10001.1 meg_lanning Meghann Lanning Australia 1992-03-25 Right-hand bat Right-arm leg break ... ``` ``` -------------------------------- ### Access Competition Codes Source: https://context7.com/robjhyndman/cricketdata/llms.txt Reference the cricsheet_codes dataset to identify valid competition identifiers for data fetching. ```r library(cricketdata) # View all available competition codes cricsheet_codes ``` ```r cricsheet_codes |> dplyr::filter(grepl("Women", competition)) ``` -------------------------------- ### find_player_id - Search for Player IDs Source: https://context7.com/robjhyndman/cricketdata/llms.txt Searches ESPNCricinfo for players matching a name string and returns their player IDs. Up to 100 matches are returned per search. ```APIDOC ## find_player_id - Search for Player IDs on ESPNCricinfo ### Description Searches ESPNCricinfo for players matching a name string and returns their player IDs, which are required for fetching individual player statistics. Returns up to 100 matches per search; use specific names for better results. ### Method GET ### Endpoint /find_player_id ### Parameters #### Query Parameters - **name** (string or vector of strings) - Required - The name(s) of the player(s) to search for. ### Request Example ```r library(cricketdata) # Search for a player by name perry_search <- find_player_id("Perry") print(perry_search) # Search for multiple players at once players <- find_player_id(c("Meg Lanning", "Virat Kohli")) print(players) ``` ### Response #### Success Response (200) - **ID** (numeric) - The unique player ID on ESPNCricinfo. - **Name** (string) - The full name of the player. - **searchstring** (string) - The name string used for searching. - **Country** (string) - The country the player represents. - **Played** (string) - The years the player has been active. #### Response Example ```r # A tibble: 12 x 5 ID Name searchstring Country Played 1 275487 Ellyse Perry Perry Australia 2007-2024 2 253802 Fred Perry Perry England 1920-1930 ... ``` ``` -------------------------------- ### Search for Player IDs with find_player_id Source: https://context7.com/robjhyndman/cricketdata/llms.txt Searches ESPNCricinfo for player IDs using names. Use specific names to improve search accuracy as the function returns up to 100 matches. ```r library(cricketdata) # Search for a player by name perry_search <- find_player_id("Perry") perry_search #> # A tibble: 12 x 5 #> ID Name searchstring Country Played #> #> 1 275487 Ellyse Perry Perry Australia 2007-2024 #> 2 253802 Fred Perry Perry England 1920-1930 #> ... # Search for multiple players at once players <- find_player_id(c("Meg Lanning", "Virat Kohli")) players #> # A tibble: 2 x 5 #> ID Name searchstring Country Played #> #> 1 329336 Meg Lanning Meg Lanning Australia 2010-2024 #> 2 253802 Virat Kohli Virat Kohli India 2008-2024 # Get specific player ID for data fetching meg_lanning_id <- find_player_id("Meg Lanning")$ID[1] # Use this ID with fetch_player_data() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.