Skip to contents

This is an experimental function that allows you to apply a suffix/symbol to only the first row of a table, and maintain the alignment with whitespace in the remaining rows.

Usage

fmt_symbol_first(
  gt_object,
  column = NULL,
  symbol = NULL,
  suffix = "",
  decimals = NULL,
  last_row_n = NULL,
  symbol_first = FALSE,
  scale_by = NULL,
  gfont = NULL
)

Arguments

gt_object

An existing gt table object of class gt_tbl

column

columns to apply color to with tidyeval

symbol

The HTML code or raw character string of the symbol being inserted, optionally

suffix

a suffix to add, optionally

decimals

the number of decimal places to round to

last_row_n

Defining the last row to apply this to. The function will attempt to guess the proper length, but you can always hardcode a specific length.

symbol_first

TRUE/FALSE - symbol before after suffix.

scale_by

A numeric value to multiply the values by. Useful for scaling percentages from 0 to 1 to 0 to 100.

gfont

A string passed to gt::google_font() - Existing Google Monospaced fonts are available at: fonts.google.com

Value

An object of class gt_tbl.

Figures

Function ID

2-1

Examples

library(gt)
fmted_tab <- gtcars %>%
  head() %>%
  dplyr::select(mfr, year, bdy_style, mpg_h, hp) %>%
  dplyr::mutate(mpg_h = rnorm(n = dplyr::n(), mean = 22, sd = 1)) %>%
  gt::gt() %>%
  gt::opt_table_lines() %>%
  fmt_symbol_first(column = mfr, symbol = "&#x24;", last_row_n = 6) %>%
  fmt_symbol_first(column = year, suffix = "%") %>%
  fmt_symbol_first(column = mpg_h, symbol = "&#37;", decimals = 1) %>%
  fmt_symbol_first(hp, symbol = "&#176;", suffix = "F", symbol_first = TRUE)