knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

suitr

Coverage status Travis build status AppVeyor Build Status

This package makes it easy to create cards in R either for printing in the console or for html export. The logic is based around the Unicode representation of cards (and other objects) which are wrapped in a span container.

Installation

You can install suitr from GitHub via install_github()

devtools::install_github("GregorDeCillia/suitr")

Cards

Cards are always represented by strings like "Kc" or "7s". They can be converted into HTML via card_html().

library(suitr)
span(card_html("Jh"), card_html("As"), card_html("Tc"), card_html("2d"))

card_unicode() converts cards into a Unicode representation which means they can be printed directly into the console.

cat(card_unicode("Ad"))

suitr uses a four color deck by default. This behavior can be changed with the parameter four_color.

card_list()
card_list() %>% lapply(card_html, size = 50) %>% span()

card_list() %>% lapply(card_html, size = 50, four_color = FALSE) %>% span()

Suits

It is also possible to get the Unicode representation of the suits symbols and export them into html.

suit_list()
suit_list() %>% lapply(suit_html) %>% span()

suit_list() %>% lapply(suit_html, fill = FALSE) %>% span()

suit_list() %>% sapply(suit_unicode) %>% cat()

Special cards

There are currently r length(card_specials()) "special" cards implemented which do not match the rank-suit pattern of the cards above. Those are wrapped into a named list which can be obtained with card_specials().

names(card_specials())
card_specials() %>% lapply(unicode_html, style = "color: blue;") %>% span()

Dice

1:6 %>% lapply(dice_html, size = 140) %>% span()

Chess

pieces_list()
pieces_list() %>% lapply(chess_html, size = 140) %>% span()

pieces_list() %>% lapply(chess_html, color = "black", size = 140) %>% span()

Mahjong

mahjong_list()[1:4]
mahjong_list() %>% lapply(mahjong_html, size = 68) %>% span()

Domino

span(domino_html(4, 5), domino_html(0, 6), domino_html(6, 2, horizontal = FALSE))

Draughts

span(draughts_html("white", "man"), draughts_html("white", "king"),
     draughts_html("black", "man"), draughts_html("black", "king")) %>% browsable()


r-webutils/suitr documentation built on Dec. 23, 2021, 12:18 a.m.