save_pgn: Save chess game data in the PGN format

View source: R/save_pgn.R

save_pgnR Documentation

Save chess game data in the PGN format

Description

A no-frills function to save a data frame of chess games in the portable game notation (PGN) format.

Usage

save_pgn(pgn, pgn_path, append = FALSE)

Arguments

pgn

A data frame or tibble of the games to be saved.

pgn_path

A single-element character vector of the path where the PGN file should be saved.

append

(Default = FALSE) A single-element boolean vector indicating whether to overwrite or append data to an already existing file.

Details

The data frame (or tibble) to be saved as a PGN file should have a column for each desired tag. In addition, the table should have a column named Movetext containing the moves of each game in standard algebraic notation (SAN). The table should contain one game per row. It is currently up to the user to ensure that the movetext is valid SAN, since save_pgn() will do nothing to check the validity.

The PGN format requires tag names to begin with an uppercase letter, and to consist only of letters, digits, or underscores.See the PGN specification for information on the PGN format.

If any tags in the Seven Tag Roster are missing, save_pgn() will add the missing tags and assign them values of "?" to indicate that the values are unknown. Any forbidden characters in the tag names will be replaced with underscores. If this causes duplicate tags, the duplicates will be numbered. Tag names beginning with lowercase letters will be capitalized, and those beginning with non-letters will be prepended with a capital X.

Value

save_pgn() returns NULL.

See Also

  • get_pgn() for loading PGN files.

  • clean_movetext() to strip comments and annotations.

  • evaluate_pgn() to analyze all the games in a PGN file

  • evaluate_game() to analyze a single game from a PGN file

Examples

fools_mate <- tibble::tibble(
  Event    = 'Casual Game',
  Site     = '221B Baker Street',
  Date     = '1887.04.01',
  Round    = '?',
  White    = 'Sherlock Holmes',
  Black    = 'John H. Watson',
  Result   = '1-0',
  Movetext = '1. e4 g5 2. Nc3 f5 3. Qh5# 1-0'
)
save_pgn(fools_mate, pgn_path = 'save_pgn_example.pgn')
file.remove('save_pgn_example.pgn')

dryguy/rbitr documentation built on Oct. 15, 2024, 6:18 a.m.