Format place names or column titles in a gt table or data frame with ACS data
Source:R/fmt_acs.R
fmt_acs.Rd
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.
Arguments
- data
The gt table data object
obj:<gt_tbl>
// requiredThis 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()
andstringr::str_replace()
forfmt_acs_county()
or just tostringr::str_replace()
byfmt_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 includestarts_with()
,ends_with()
,contains()
,matches()
,one_of()
,num_range()
, andeverything()
.- ...
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 defaulteverything()
results in all rows incolumns
being formatted. Alternatively, we can supply a vector of row captions withinc()
, a vector of row indices, or a select helper function. Examples of select helper functions includestarts_with()
,ends_with()
,contains()
,matches()
,one_of()
,num_range()
, andeverything()
. 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
// requiredEither a single formatting function or a named list of functions.
- column_title_col
Column title column.