chess includes a total of 61 games so you can get up and running as soon as you install the package. To access them, use the system.file()
function as below:
library(chess)
# Read final game from the Queen's Gambit
file <- system.file("harmon.pgn", package = "chess")
harmon_borgov <- read_game(file)
# PGN for game
str(harmon_borgov)
The example above loads the final game from the Queen’s Gambit. The other 60 games are sourced from My 60 Memorable Games, a classic book by Bobby Fischer, and are included in a single file. They can be loaded in the same way:
# Read all games from My 60 Memorable Games
file <- system.file("m60mg.pgn", package = "chess")
m60mg <- read_game(file)
# Check if it's a list of 60 games
length(m60mg)
In cases where you have more than one game in a single file, you can either load them all and access them like in a list (see below) or use the n_max
argument to read only a handful of them.
# PGN for Fischer vs. Unzicker
str(m60mg[[10]])