Package 'chessR'

Title: Functions to Extract, Clean and Analyse Online Chess Game Data
Description: A set of functions to enable users to extract chess game data from popular chess sites, including 'Lichess'<https://lichess.org/> and 'Chess.com' <https://www.chess.com/> and then perform analysis on that game data.
Authors: Jason Zivkovic [aut, cre], Jonathan Carroll [ctb] (ORCID: <https://orcid.org/0000-0002-1404-5264>), Dan Wakeling [ctb]
Maintainer: Jason Zivkovic <[email protected]>
License: GPL-3
Version: 1.5.5
Built: 2026-09-19 01:45:48 UTC
Source: https://github.com/JaseZiv/chessR

Help Index


Check Status function

Description

Check Status function

Usage

check_status(res)

Arguments

res

Response from API


Get Top 50 on chess.com Leaderboards

Description

This function takes in one parameter, the game_type, and returns a data frame of the top 50 players on chess.com.

Usage

chessdotcom_leaderboard(game_type = "daily")

Arguments

game_type

A valid chess.com game type to return the leaderboard for

Details

The leaderboard options (games) include:

"daily", "daily960", "live_rapid", "live_blitz", "live_bullet", "live_bughouse", "live_blitz960", "live_threecheck" , "live_crazyhouse", "live_kingofthehill", "lessons", "tactics"

Value

a dataframe of the chess.com top 50 players based on game_type selected

Examples

## Not run: 
chessdotcom_leaderboard(game_type = "daily")

## End(Not run)

chessR: A package for extracting and analysing chess game data

Description

This package is designed to aid in the extraction and analysis of game data from the popular chess.com

Author(s)

Maintainer: Jason Zivkovic [email protected]

Other contributors:

See Also

Useful links:


Extract moves from a game as a data.frame

Description

Extract moves from a game as a data.frame

Usage

extract_moves(moves_string)

Arguments

moves_string

string containing moves built by 'chessR' (e.g. from https://www.chess.com/) or the filename of a PGN file

Value

cleaned moves as a data.frame


Extract moves and create 'chess' game

Description

Extract moves and create 'chess' game

Usage

extract_moves_as_game(game)

Arguments

game

a single row of a 'data.frame' provided by 'chessR' containing move information or the filename of a PGN file

Value

a [chess::game()] game object


Extract Single Player's Game Data

Description

get_each_player returns a dataframe of all of the games played by one player

Usage

get_each_player(username)

Arguments

username

A string value of a player's name

Details

This function will take in a single player's username and return the data on all the games they have played on chess.com


Get Single Player Raw chess.com Game Data

Description

This function returns the raw json data for a player's chess.com data as a data frame

Usage

get_each_player_chessdotcom(username, year_month)

Arguments

username

A valid username from chess.com

year_month

An integer of YYYYMM

Value

a dataframe of chess.com data


Extract Chess Game Data

Description

get_game_data returns a dataframe of game data for either a single user or a list of usernames

Usage

get_game_data(usernames)

Arguments

usernames

A character vector of player usernames from chess.com

Details

This function will take in a list of player usernames and return a dataframe of game metadata

Value

a dataframe of chess.com data plus additional analysis columns

Examples

## Not run: 
chess_analysis_single <- get_game_data(usernames = "JaseZiv")
chess_analysis_multiple <- get_game_data(usernames = c("JaseZiv", "Smudgy1"))

## End(Not run)

Return the game ending

Description

This function returns a character vector of how the game ended from chess.dom.

Usage

get_game_ending(termination_string, white, black)

Arguments

termination_string

A character vector in the chess.com extracted data frame called 'Termination'

white

A character vector in the chess.com extracted data frame called 'White' for the player on white

black

A character vector in the chess.com extracted data frame called 'Black' for the player on black

Value

A character vector of the game ending for each game

Examples

## Not run: 
get_game_ending(termination_string = df$Termination, df$White, df$Black)

## End(Not run)

Get Raw chess.com Game Data

Description

This function returns the raw json data for a player's or list of players' chess.com data as a data frame, for all or select months played

Usage

get_raw_chessdotcom(usernames, year_month = NA_integer_)

Arguments

usernames

A vector of a valid username or usernames from chess.com

year_month

An integer of YYYYMM

Value

a dataframe of chessdotcom data

Examples

## Not run: 
get_raw_chessdotcom(usernames = "JaseZiv")
get_raw_chessdotcom(usernames = "JaseZiv", year_month = c(202112:202201))
get_raw_chessdotcom(usernames = c("JaseZiv", "Smudgy1"), year_month = 202201)

## End(Not run)

Get Raw Lichess Game Data

Description

This function returns the raw json data for a player's or list of players' Lichess data as a data frame

Usage

get_raw_lichess(player_names, since = NULL, until = NULL)

Arguments

player_names

A vector of a valid username or usernames from Lichess

since

Games played since this date. An object of class 'Date' or a string of the form '"yyyy-mm-dd"'. If 'NULL', defaults to account creation date.

until

Games played until this date. An object of class 'Date' or a string of the form '"yyyy-mm-dd"'. If 'NULL', defaults to now.

Value

a dataframe of lichess data

Examples

## Not run: 
georges_data <- get_raw_lichess(player_names = "Georges")
the_knife_data <- get_raw_lichess("the_knife", since = "2023-08-13", until = "2023-08-14")

## End(Not run)

Return the game winner

Description

This function returns a character vector of the usernames of the game winners

Usage

get_winner(result_column, white, black)

Arguments

result_column

A character vector in the extracted data frame called 'Result'

white

A character vector in the extracted data frame called 'White' for the player on white

black

A character vector in the extracted data frame called 'Black' for the player on black

Value

A character vector of the game ending for each game

Examples

## Not run: 
get_winner(df$Result, df$White, df$Black)

## End(Not run)

Get Time Information from Lichess Game Data

Description

This function returns a data frame of Lichess data with clock and move times

Usage

lichess_clock_move_time(games_list)

Arguments

games_list

A data frame of lichess data which can be generated from chessR::get_raw_lichess("username")

Value

a data frame of lichess data with move time, clock time, and move numbers

Examples

## Not run: 
lordy_leroy_data <- get_raw_lichess(player_names = "LordyLeroy")
lordy_leroy_data_with_times <- lichess_clock_move_time(games_list = lordy_leroy_data)

## End(Not run)

Get top players on Lichess leaderboards

Description

This function takes in two parameters; how many players you want returned (max 200) and the speed variant. The result is a data frame for each game type

Usage

lichess_leaderboard(top_n_players, speed_variant)

Arguments

top_n_players

The number of players (up to 200) you want returned

speed_variant

A valid lichess speed variant to return the leaderboard for

Details

The leaderboard speed variant options include:

"ultraBullet", "bullet", "blitz", "rapid", "classical", "chess960", "crazyhouse", "antichess" , "atomic", "horde", "kingOfTheHill", "racingKings", "threeCheck"

Value

a dataframe of the lichess top players based on speed_variant and top_n_players selected

Examples

## Not run: 
top10_blitz <- lichess_leaderboard(top_n_players = 10, speed_variant = "blitz")
leaderboards <- purrr::map2_df(top_n_players = 10, c("ultraBullet", "bullet"), lichess_leaderboard)

## End(Not run)

Plot a game

Description

Plot a game

Usage

plot_moves(game, interactive = TRUE, sleep = 1)

Arguments

game

a [chess::game()] object, likely with moves identified

interactive

wait for 'Enter' after each move? Turn off to use in a gif

sleep

how long to wait between moves

Value

'NULL', (invisibly) - called for the side-effect of plotting

Examples

## Not run: 
hikaru <- get_each_player_chessdotcom("hikaru", "202112")
m <- extract_moves_as_game(hikaru[11, ])
plot_moves(m)

## End(Not run)

Return the number of moves in a game

Description

This function returns the number of moves played in each game. The function accepts a vector of chess Moves data in PGN notation, usually called 'Moves'

Usage

return_num_moves(moves_string)

Arguments

moves_string

A character vector of chess Moves data in PGN notation usually called 'Moves' in extracted data

Value

A numeric vector of the number of moves in each game

Examples

## Not run: 
return_num_moves(moves_string = df$Moves)

## End(Not run)