Skip to contents

`card_symbol()` retrieves the suit_symbol field from a vctrs "card" record (class "card"). When applied to a plain character vector, it returns the vector unchanged. This function was specifically designed to work with vctrs "card" objects created by create_shuffled_deck().

Usage

card_symbol(x, ...)

Arguments

x

A `card` object (created by `create_shuffled_deck()`) or a character vector of suit symbols (e.g., "♠", "♥").

...

Additional arguments passed to methods. Not used.

Value

Depending on the method:

card

A character vector containing the `suit_symbol` field of each card.

character

The input character vector, unchanged.

Details

- For objects of class "card", card_symbol.card(x) extracts the suit_symbol field via vctrs::field(x, "suit_symbol"), returning a character vector of card suit symbols (e.g., "♠", "♥", "♦"). - If x is a character vector, card_symbol.character(x) simply returns x unchanged. - For any other class, card_symbol.default(x) throws an error.

Examples

deck <- create_shuffled_deck()
card_symbol(deck)
#>   [1] "♠" "♥" "♠" "♣" "♥" "♥" "♦" "♦" "♠" "♥" "♥" "♠" "♠" "♣" "♥" "♦" "♠" "♣"
#>  [19] "♠" "♦" "♣" "♥" "♠" "♣" "♦" "♦" "♠" "♦" "♣" "♠" "♣" "♥" "♠" "♥" "♦" "♣"
#>  [37] "♦" "♥" "♣" "♦" "♥" "♦" "♥" "♠" "♣" "♠" "♥" "♣" "♣" "♥" "♣" "♣" "♥" "♣"
#>  [55] "♠" "♠" "♠" "♠" "♠" "♥" "♣" "♥" "♥" "♠" "♣" "♥" "♥" "♦" "♦" "♥" "♥" "♠"
#>  [73] "♠" "♣" "♠" "♥" "♦" "♣" "♣" "♣" "♣" "♣" "♦" "♦" "♦" "♥" "♠" "♠" "♠" "♥"
#>  [91] "♦" "♥" "♠" "♠" "♠" "♥" "♥" "♣" "♦" "♦" "♠" "♠" "♠" "♦" "♥" "♠" "♠" "♥"
#> [109] "♣" "♥" "♣" "♥" "♣" "♠" "♦" "♦" "♣" "♣" "♦" "♥" "♦" "♦" "♠" "♣" "♥" "♦"
#> [127] "♠" "♣" "♣" "♦" "♥" "♠" "♠" "♦" "♣" "♥" "♦" "♦" "♥" "♣" "♦" "♥" "♥" "♣"
#> [145] "♠" "♦" "♥" "♦" "♦" "♠" "♥" "♣" "♣" "♦" "♣" "♦" "♠" "♣" "♠" "♦" "♦" "♥"
#> [163] "♣" "♦" "♣" "♠" "♠" "♥" "♥" "♦" "♣" "♣" "♦" "♠" "♥" "♠" "♠" "♥" "♦" "♣"
#> [181] "♠" "♣" "♦" "♥" "♥" "♣" "♣" "♣" "♠" "♣" "♣" "♠" "♠" "♦" "♥" "♦" "♦" "♥"
#> [199] "♦" "♠" "♦" "♣" "♦" "♥" "♦" "♥" "♦" "♣"

card_symbol(c("♠", "♦", "♣"))
#> [1] "♠" "♦" "♣"