Skip to content

Conversation

@rich-iannone
Copy link
Member

For those times where you have logical values in a gt table, you might want to express them in a slightly different way. You could express as a 'yes' or 'no', a 'true' or 'false', or, perhaps use pairings of complementary symbols that make sense in a table. The fmt_tf() function has a set of tf_style presets that can be used to quickly map TRUE/FALSE values to strings (which are automatically translated according to a given locale value), or, symbols like up/down or left/right arrows and open/closed shapes.

Here's an example of this, using the sp500 dataset:

library(tidyverse)
library(gt)

sp500 |>
  dplyr::filter(date >= "2013-01-07" & date <="2013-01-12") |>
  dplyr::arrange(date) |>
  dplyr::select(-c(adj_close, volume, high, low)) |>
  gt(rowname_col = "date") |>
  cols_add(dir = close > open, .after = open) |>
  fmt_tf(
    columns = dir,
    tf_style = "arrows",
    colors = c("green", "red")
  ) |>
  fmt_currency(columns = c(open, close)) |>
  cols_label(
    open = "Opening",
    close = "Closing",
    dir = ""
  )
man_fmt_tf_1

Fixes: #1650

@rich-iannone rich-iannone merged commit 39b58b2 into master May 9, 2024
@rich-iannone rich-iannone deleted the add-fmt-tf branch May 9, 2024 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Format logical values

2 participants