R/python.R

Defines functions .onLoad install_chess

Documented in install_chess

#' Install python-chess
#'
#' Install the python library used as the backbone of this package. You can
#' pass arguments on to [reticulate::py_install()], but `python-chess` needs
#' `python_version = "3.8"` and `pip = TRUE`.
#'
#' @param method Installation method
#' @param conda The path to a conda executable
#' @param ... Other arguments passed on to [reticulate::py_install()]
#' @export
install_chess <- function(method = "auto", conda = "auto", ...) {
  reticulate::py_install(
    "chess",
    method = method, conda = conda,
    python_version = "3.8", pip = TRUE, ...
  )
}

# Environment for globals
chess_env <- new.env(parent = emptyenv())

# Load python-chess
.onLoad <- function(libname, pkgname) {
  reticulate::configure_environment(pkgname)

  assign("chess_svg", reticulate::import("chess.svg", delay_load = TRUE), chess_env)
  assign("chess_pgn", reticulate::import("chess.pgn", delay_load = TRUE), chess_env)
}

Try the chess package in your browser

Any scripts or data that you put into this service are public.

chess documentation built on Jan. 13, 2021, 8:31 p.m.