Skip to content

Add the fmt_tf() function #1654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 57 commits into from
May 9, 2024
Merged

Add the fmt_tf() function #1654

merged 57 commits into from
May 9, 2024

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
11 checks passed
@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
1 participant