Skip to contents

fmt_acs_county() is helpful for stripping the state name from county-level ACS data and fmt_acs_minutes() does the same for a column with a duration (e.g. commute times). If data is not a gt_tbl object, both function can use dplyr::mutate() to transform a standard data frame.

Usage

fmt_acs_county(
  data,
  state = NULL,
  pattern = ", {state}",
  replacement = "",
  name_col = "NAME",
  columns = dplyr::all_of(name_col),
  ...
)

fmt_acs_minutes(
  data,
  pattern = "[:space:]minutes$",
  replacement = "",
  column_title_col = "column_title",
  columns = dplyr::all_of(column_title_col),
  ...
)

Arguments

data

The gt table data object

obj:<gt_tbl> // required

This is the gt table object that is commonly created through use of the gt() function.

state

State name. Required if state is included in pattern.

pattern

Passed to glue::glue() and stringr::str_replace() for fmt_acs_county() or just to stringr::str_replace() by fmt_acs_minutes(). Defaults to ", {state}" which strips the state name from a column of county-level name values or "[:space:]minutes$" which strips the trailing text for minutes.

replacement

Passed to stringr::str_replace(). Defaults to "".

name_col

Name for column with place name values. Defaults to "NAME"

columns

Columns to target

<column-targeting expression> // default: everything()

Can either be a series of column names provided in c(), a vector of column indices, or a select helper function. Examples of select helper functions include starts_with(), ends_with(), contains(), matches(), one_of(), num_range(), and everything().

...

Arguments passed on to gt::fmt

rows

Rows to target

<row-targeting expression> // default: everything()

In conjunction with columns, we can specify which of their rows should undergo formatting. The default everything() results in all rows in columns being formatted. Alternatively, we can supply a vector of row captions within c(), a vector of row indices, or a select helper function. Examples of select helper functions include starts_with(), ends_with(), contains(), matches(), one_of(), num_range(), and everything(). We can also use expressions to filter down to the rows we need (e.g., [colname_1] > 100 & [colname_2] < 50).

compat

Formatting compatibility

vector<character> // default: NULL (optional)

An optional vector that provides the compatible classes for the formatting. By default this is NULL.

fns

Formatting functions

function|list of functions // required

Either a single formatting function or a named list of functions.

column_title_col

Column title column.