diff --git a/NAMESPACE b/NAMESPACE index 97b96d01c0..172965c0ff 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -130,6 +130,7 @@ export(fmt_percent) export(fmt_roman) export(fmt_scientific) export(fmt_spelled_num) +export(fmt_tf) export(fmt_time) export(fmt_units) export(fmt_url) diff --git a/R/data_color.R b/R/data_color.R index 6f9bf37e26..2ce319d6ab 100644 --- a/R/data_color.R +++ b/R/data_color.R @@ -678,7 +678,7 @@ #' #' @family data formatting functions #' @section Function ID: -#' 3-35 +#' 3-36 #' #' @section Function Introduced: #' `v0.2.0.5` (March 31, 2020) diff --git a/R/format_data.R b/R/format_data.R index 5c3b063fed..6e96c35c7a 100644 --- a/R/format_data.R +++ b/R/format_data.R @@ -8399,6 +8399,692 @@ format_bins_by_context <- function(x, sep, fmt, context) { x_str } + +#' Format `TRUE` and `FALSE` values +#' +#' @description +#' +#' There can be times where logical values are useful in a **gt** table. You +#' might want to express 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. +#' +#' While the presets are nice, you can provide your own mappings through the +#' `true_val` and `false_val` arguments. With those you could provide text +#' (perhaps a Unicode symbol?) or even a **fontawesome** icon by using +#' `fontawesome::fa("")`. The function will automatically handle +#' alignment when `auto_align = TRUE` and try to give you the best look +#' depending on the options chosen. For extra customization, you can also apply +#' color to the individual `TRUE`, `FALSE`, and `NA` mappings. Just supply +#' a vector of colors (up to a length of 3) to the `colors` argument. +#' +#' @inheritParams fmt_number +#' +#' @param tf_style *Predefined style for `TRUE`/`FALSE` formatting* +#' +#' `scalar|scalar(1<=val<=10)` // *default:* `"true-false"` +#' +#' The `TRUE`/`FALSE` mapping style to use. By default this is the short name +#' `"true-false"` which corresponds to the words 'true' and 'false'. Two other +#' `tf_style` values produce words: `"yes-no"` and `"up-down"`. All three of +#' these options for `tf_style` are locale-aware through the `locale` option, +#' so, a `"yes"` value will instead be `"ja"` when `locale = "de"`. Options +#' 4 through to 10 involve pairs of symbols (e.g., `"check-mark"` displays +#' a check mark for `TRUE` and an X symbol for `FALSE`). +#' +#' @param true_val *Text to use for `TRUE` values* +#' +#' `scalar` // *default:* `NULL` (`optional`) +#' +#' While the choice of a `tf_style` will typically supply the `true_val` and +#' `false_val` text, we could override this and supply text for any `TRUE` +#' values. This doesn't need to be used in conjunction with `false_val`. +#' +#' @param false_val *Text to use for `FALSE` values* +#' +#' `scalar` // *default:* `NULL` (`optional`) +#' +#' While the choice of a `tf_style` will typically supply the `true_val` and +#' `false_val` text, we could override this and supply text for any `FALSE` +#' values. This doesn't need to be used in conjunction with `true_val`. +#' +#' @param na_val *Text to use for `NA` values* +#' +#' `scalar` // *default:* `NULL` (`optional`) +#' +#' None of the `tf_style` presets will replace any missing values encountered +#' in the targeted cells. While we always have the option to use +#' [sub_missing()] for `NA` replacement, we have the opportunity to do that +#' here with the `na_val` option. This is useful because we also have the +#' means to add color to the `na_val` text or symbol and doing that requires +#' that a replacement value for `NA`s is specified here. +#' +#' @param colors *Colors to use for the resulting strings or symbols* +#' +#' `vector` // *default:* `NULL` (`optional`) +#' +#' Providing a vector of color values to `colors` will progressively add color +#' to the formatted result depending on the number of colors provided. With a +#' single color, all formatted values will be in that color. Giving two colors +#' results in `TRUE` values being the first color, and `FALSE` values +#' receiving the second. With the three color option, the final color will be +#' given to any `NA` values replaced through `na_val`. +#' +#' @param auto_align *Automatic alignment of the formatted column* +#' +#' `scalar` // *default:* `TRUE` +#' +#' The input values may have resulted in an alignment that is not as suitable +#' once formatting has occurred. With `auto_align = TRUE`, the formatted +#' values will be inspected and this may result in a favorable change in +#' alignment. Typically, symbols will be center aligned whereas words will +#' receive a left alignment (for words in LTR languages). +#' +#' @return An object of class `gt_tbl`. +#' +#' @section Compatibility of formatting function with data values: +#' +#' The `fmt_tf()` formatting function is compatible with body cells that are +#' of the `"logical"` (preferred) or `"numeric"` types. Any other types of body +#' cells are ignored during formatting. This is to say that cells of +#' incompatible data types may be targeted, but there will be no attempt to +#' format them. +#' +#' There is a special caveat when attempting to format numerical values: the +#' values must either be exactly `1` (the analogue for `TRUE`) or exactly `0` +#' (the analogue for `FALSE`). Any other numerical values will be disregarded +#' and left as is. Because of these restrictions, it is recommended that only +#' logical values undergo formatting. +#' +#' @section Targeting cells with `columns` and `rows`: +#' +#' Targeting of values is done through `columns` and additionally by `rows` (if +#' nothing is provided for `rows` then entire columns are selected). The +#' `columns` argument allows us to target a subset of cells contained in the +#' resolved columns. We say resolved because aside from declaring column names +#' in `c()` (with bare column names or names in quotes) we can use +#' **tidyselect**-style expressions. This can be as basic as supplying a select +#' helper like `starts_with()`, or, providing a more complex incantation like +#' +#' `where(~ is.numeric(.x) && max(.x, na.rm = TRUE) > 1E6)` +#' +#' which targets numeric columns that have a maximum value greater than +#' 1,000,000 (excluding any `NA`s from consideration). +#' +#' By default all columns and rows are selected (with the `everything()` +#' defaults). Cell values that are incompatible with a given formatting function +#' will be skipped over, like `character` values and numeric `fmt_*()` +#' functions. So it's safe to select all columns with a particular formatting +#' function (only those values that can be formatted will be formatted), but, +#' you may not want that. One strategy is to format the bulk of cell values with +#' one formatting function and then constrain the columns for later passes with +#' other types of formatting (the last formatting done to a cell is what you get +#' in the final output). +#' +#' Once the columns are targeted, we may also target the `rows` within those +#' columns. This can be done in a variety of ways. If a stub is present, then we +#' potentially have row identifiers. Those can be used much like column names in +#' the `columns`-targeting scenario. We can use simpler **tidyselect**-style +#' expressions (the select helpers should work well here) and we can use quoted +#' row identifiers in `c()`. It's also possible to use row indices (e.g., +#' `c(3, 5, 6)`) though these index values must correspond to the row numbers of +#' the input data (the indices won't necessarily match those of rearranged rows +#' if row groups are present). One more type of expression is possible, an +#' expression that takes column values (can involve any of the available columns +#' in the table) and returns a logical vector. This is nice if you want to base +#' formatting on values in the column or another column, or, you'd like to use a +#' more complex predicate expression. +#' +#' @section Compatibility of arguments with the `from_column()` helper function: +#' +#' The [from_column()] helper function can be used with certain arguments of +#' `fmt_tf()` to obtain varying parameter values from a specified column within +#' the table. This means that each row could be formatted a little bit +#' differently. These arguments provide support for [from_column()]: +#' +#' - `tf_style` +#' - `pattern` +#' - `true_val` +#' - `false_val` +#' - `na_val` +#' - `locale` +#' +#' Please note that for each of the aforementioned arguments, a [from_column()] +#' call needs to reference a column that has data of the correct type (this is +#' different for each argument). Additional columns for parameter values can be +#' generated with the [cols_add()] function (if not already present). Columns +#' that contain parameter data can also be hidden from final display with +#' [cols_hide()]. Finally, there is no limitation to how many arguments the +#' [from_column()] helper is applied so long as the arguments belong to this +#' closed set. +#' +#' @section Formatting with the `tf_style` argument: +#' +#' We can supply a preset `TRUE`/`FALSE` style to the `tf_style` argument to +#' handle the formatting of logical values. There are several such styles and +#' the first three of them can handle localization to any supported locale +#' (i.e., the pairs of words for each style will be translated to the language +#' of the `locale`) value. +#' +#' The following table provides a listing of all valid `tf_style` values and a +#' description of their output values. The output from styles `4` to `10` are +#' described in terms of the Unicode character names used for the `TRUE` and +#' `FALSE` values. +#' +#' | | TF Style | Output (for `TRUE` and `FALSE`) | +#' |----|---------------|-------------------------------------------------| +#' | 1 | `"true-false"`| `"true"`, `"false"` (`locale`-aware) | +#' | 2 | `"yes-no"` | `"yes"`, `"no"` (`locale`-aware) | +#' | 3 | `"up-down"` | `"up"`, `"down"` (`locale`-aware) | +#' | 4 | `"check-mark"`| ``, `` | +#' | 5 | `"circles"` | ``, `` | +#' | 6 | `"squares"` | ``, `` | +#' | 7 | `"diamonds"` | ``, `` | +#' | 8 | `"arrows"` | ``, `` | +#' | 9 | `"triangles"` | ``, ``| +#' | 10 | `"triangles-lr"`| ``, `` | +#' +#' @section Adapting output to a specific `locale`: +#' +#' This formatting function can adapt outputs according to a provided `locale` +#' value. Examples include `"en"` for English (United States) and `"fr"` for +#' French (France). Note that a `locale` value provided here will override any +#' global locale setting performed in [gt()]'s own `locale` argument (it is +#' settable there as a value received by all other functions that have a +#' `locale` argument). As a useful reference on which locales are supported, we +#' can use the [info_locales()] function to view an info table. +#' +#' @section Examples: +#' +#' Let's use a subset of the [`sp500`] dataset to create a small **gt** table +#' containing opening and closing price data for a week in 2013. We can add +#' a logical column (`dir`) with the [cols_add()] function; the expression used +#' determines whether the `close` value is greater than the `open` value. That +#' new column is inserted between `open` and `close`. Then, we use the +#' `fmt_tf()` function to generate up and down arrows in the `dir` column. We +#' elect to use green upward arrows and red downward arrows (through the +#' `colors` option). With a little numeric formatting and changes to the column +#' labels, the table becomes more presentable. +#' +#' ```r +#' 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 = "" +#' ) +#' ``` +#' +#' \if{html}{\out{ +#' `r man_get_image_tag(file = "man_fmt_tf_1.png")` +#' }} +#' +#' The [`reactions`] dataset contains chemical kinetic information on a wide +#' variety of atmospherically-relevant compounds. It might be interesting to get +#' a summary (for a small subset of compounds) for which rate constants are +#' available for the selected compounds. We first start by selecting the +#' relevant rows and columns. Then we generate logical columns for each of the +#' reaction types (i.e., if a value is `NA` then there's no measurement, so +#' that's `FALSE`). Once the **gt** table has been created, we can use +#' `fmt_tf()` to provide open and filled circles to indicate whether a +#' particular reaction has been measured and presented in the literature. +#' +#' ```r +#' reactions |> +#' dplyr::filter(cmpd_type %in% c("carboxylic acid", "alkyne", "allene")) |> +#' dplyr::select(cmpd_name, cmpd_type, ends_with("k298")) |> +#' dplyr::mutate(across(ends_with("k298"), is.na)) |> +#' gt(rowname_col = "cmpd_name", groupname_col = "cmpd_type") |> +#' tab_spanner( +#' label = "Has a measured rate constant", +#' columns = ends_with("k298") +#' ) |> +#' tab_stub_indent( +#' rows = everything(), +#' indent = 2 +#' ) |> +#' fmt_tf( +#' columns = ends_with("k298"), +#' tf_style = "circles" +#' ) |> +#' cols_label( +#' OH_k298 = "OH", +#' O3_k298 = "Ozone", +#' NO3_k298 = "Nitrate", +#' Cl_k298 = "Chlorine" +#' ) |> +#' cols_width( +#' stub() ~ px(200), +#' ends_with("k298") ~ px(80) +#' ) |> +#' opt_vertical_padding(scale = 0.35) +#' ``` +#' +#' \if{html}{\out{ +#' `r man_get_image_tag(file = "man_fmt_tf_2.png")` +#' }} +#' +#' There are census-based population values in the [`towny`] dataset and quite a +#' few small towns within it. Let's look at the ten smallest towns (according +#' to the 2021 figures) and work out whether their populations have increased or +#' declined since 1996. Also, let's determine which of these towns even have a +#' website. After that data preparation, the data is made into a **gt** table +#' and `fmt_tf()` can be used in the `website` and `pop_dir` columns (which both +#' have `TRUE`/`FALSE` values). Each of these `fmt_tf()` calls will either +#' produce `"yes"`/`"no"` or `"up"`/`"down"` strings (set via the `tf_style` +#' option). +#' +#' ```r +#' towny |> +#' dplyr::arrange(population_2021) |> +#' dplyr::mutate(website = !is.na(website)) |> +#' dplyr::mutate(pop_dir = population_2021 > population_1996) |> +#' dplyr::select(name, website, population_1996, population_2021, pop_dir) |> +#' dplyr::slice_head(n = 10) |> +#' gt(rowname_col = "name") |> +#' tab_spanner( +#' label = "Population", +#' columns = starts_with("pop") +#' ) |> +#' tab_stubhead(label = "Town") |> +#' fmt_tf( +#' columns = website, +#' tf_style = "yes-no", +#' auto_align = FALSE +#' ) |> +#' fmt_tf( +#' columns = pop_dir, +#' tf_style = "up-down", +#' pattern = "It's {x}." +#' ) |> +#' cols_label_with( +#' columns = starts_with("population"), +#' fn = function(x) sub("population_", "", x) +#' ) |> +#' cols_label( +#' website = md("Has a \n website?"), +#' pop_dir = "Pop. direction?" +#' ) |> +#' opt_horizontal_padding(scale = 2) +#' ``` +#' +#' \if{html}{\out{ +#' `r man_get_image_tag(file = "man_fmt_tf_3.png")` +#' }} +#' +#' If formatting to words instead of symbols (with the hyphenated `tf_style` +#' keywords), the words themselves can be translated to different languages +#' if providing a `locale` value. In this next example, we're manually creating +#' a tibble with locale codes and their associated languages. The `yes` and `up` +#' columns all receive `TRUE` whereas `no` and `down` will all be `FALSE`. +#' With two calls of `fmt_tf()` for each of these pairings, we get the columns' +#' namesake words. To have these words translated, the `locale` argument is +#' pointed toward values in the `code` column by using the [from_column()] +#' helper function. +#' +#' ```r +#' dplyr::tibble( +#' code = c("de", "fr", "is", "tr", "ka", "lt", "ca", "bg", "lv"), +#' lang = c( +#' "German", "French", "Icelandic", "Turkish", "Georgian", +#' "Lithuanian", "Catalan", "Bulgarian", "Latvian" +#' ), +#' yes = TRUE, +#' no = FALSE, +#' up = TRUE, +#' down = FALSE +#' ) |> +#' gt(rowname_col = "lang") |> +#' tab_header(title = "Common words in a few languages") |> +#' fmt_tf( +#' columns = c(yes, no), +#' tf_style = "yes-no", +#' locale = from_column("code") +#' ) |> +#' fmt_tf( +#' columns = c(up, down), +#' tf_style = "up-down", +#' locale = from_column("code") +#' ) |> +#' cols_merge( +#' columns = c(lang, code), +#' pattern = "{1} ({2})" +#' ) |> +#' cols_width( +#' stub() ~ px(150), +#' everything() ~ px(80) +#' ) +#' ``` +#' +#' \if{html}{\out{ +#' `r man_get_image_tag(file = "man_fmt_tf_4.png")` +#' }} +#' +#' @family data formatting functions +#' @section Function ID: +#' 3-18 +#' +#' @section Function Introduced: +#' *In Development* +#' +#' @import rlang +#' @export +fmt_tf <- function( + data, + columns = everything(), + rows = everything(), + tf_style = "true-false", + pattern = "{x}", + true_val = NULL, + false_val = NULL, + na_val = NULL, + colors = NULL, + auto_align = TRUE, + locale = NULL +) { + + # Perform input object validation + stop_if_not_gt_tbl(data = data) + + # + # Begin support for `from_column()` objects passed to compatible arguments + # + + # Supports parameters: + # + # - tf_style + # - pattern + # - true_val + # - false_val + # - na_val + # - locale + + arg_vals <- + mget( + get_arg_names( + function_name = "fmt_tf", + all_args_except = c("data", "columns", "rows", "colors", "auto_align") + ) + ) + + if (args_have_gt_column_obj(arg_vals = arg_vals)) { + + # Resolve the row numbers using the `resolve_vars` function + resolved_rows_idx <- + resolve_rows_i( + expr = {{ rows }}, + data = data + ) + + param_tbl <- + generate_param_tbl( + data = data, + arg_vals = arg_vals, + resolved_rows_idx = resolved_rows_idx + ) + + for (i in seq_len(nrow(param_tbl))) { + + p_i <- as.list(param_tbl[i, ]) + + data <- + fmt_tf( + data = data, + columns = {{ columns }}, + rows = resolved_rows_idx[i], + tf_style = p_i$tf_style %||% tf_style, + pattern = p_i$pattern %||% pattern, + true_val = p_i$true_val %||% true_val, + false_val = p_i$false_val %||% false_val, + na_val = p_i$na_val %||% na_val, + locale = p_i$locale %||% locale + ) + } + + return(data) + } + + # + # End support for `gt_column()` objects passed to compatible arguments + # + + # Declare formatting function compatibility + compat <- c("logical", "numeric") + + # Stop function if `locale` does not have a valid value; normalize locale + # and resolve one that might be set globally + validate_locale(locale = locale) + locale <- normalize_locale(locale = locale) + locale <- resolve_locale(data = data, locale = locale) + + # If `locale` is NULL then use the 'en' locale + if (is.null(locale)) { + locale <- "en" + } + + # In this case where strict mode is being used (with the option + # called "gt.strict_column_fmt"), stop the function if any of the + # resolved columns have data that is incompatible with this formatter + if ( + !column_classes_are_valid( + data = data, + columns = {{ columns }}, + valid_classes = compat + ) + ) { + if (isTRUE(getOption("gt.strict_column_fmt", TRUE))) { + cli::cli_abort( + "The `fmt_tf()` function can only be used on `columns` + with logical or numerical data." + ) + } + } + + # Obtain the vector of `TRUE`/`FALSE` text values + tf_vals_vec <- get_tf_vals(tf_style = tf_style, locale = locale) + + # If there are any values provided to `true_val` or `false_val`, use + # those in preference to the values obtained from `get_tf_vals()` + true_val <- true_val %||% tf_vals_vec[1] + false_val <- false_val %||% tf_vals_vec[2] + + if (auto_align) { + + # As a first pass, assume that the `true_val` and `false_val` values that + # are returned from one of the styles that produce text should result in + # a left alignment of values + if ( + is.character(tf_style) && !(tf_style %in% tf_formats_text()) || + is.numeric(tf_style) && !(tf_style %in% seq_along(tf_formats_text())) + ) { + alignment <- "center" + } else { + alignment <- "left" + } + + # If an HTML entity is detected, prefer center alignment + if (grepl("^&.*", true_val) || grepl("^&.*", false_val)) { + alignment <- "center" + } + + if (nchar(true_val) <= 1 || nchar(false_val) <= 1) { + alignment <- "center" + } + + # If using SVG graphics for either of `true_val` or `false_val` then + # we'd prefer to have center alignment of the icons + if ( + grepl("^' + # when in an HTML context; this avoids the potential collapse of + # rows with only empty strings + if (!is.null(true_val) && true_val == "") { + true_val <- "
" + } + if (!is.null(false_val) && false_val == "") { + false_val <- "
" + } + if (!is.null(na_val) && na_val == "") { + na_val <- "
" + } + + true_val <- make_span_with_color(text = true_val, color = true_val_color) + false_val <- make_span_with_color(text = false_val, color = false_val_color) + na_val <- make_span_with_color(text = na_val, color = na_val_color) + } + + # Replace any `TRUE` values, or, numbers that are exactly `1` + x_str_non_missing[ + x_str_non_missing == TRUE | x_str_non_missing == 1 + ] <- true_val + + # Replace any `FALSE` values, or, numbers that are exactly `0` + x_str_non_missing[ + x_str_non_missing == FALSE | x_str_non_missing == 0 + ] <- false_val + + # Handle formatting of pattern + x_str_non_missing <- apply_pattern_fmt_x(x_str_non_missing, pattern = pattern) + + x_str[!is.na(x)] <- x_str_non_missing + x_str[is.na(x)] <- na_val %||% NA_character_ + x_str +} + +make_span_with_color <- function(text, color = NULL) { + + if (is.null(color) | is.null(text) | is.na(color)) { + return(text) + } + + paste0("", text, "") +} + #' Format measurement units #' #' @description @@ -8560,7 +9246,7 @@ format_bins_by_context <- function(x, sep, fmt, context) { #' #' @family data formatting functions #' @section Function ID: -#' 3-18 +#' 3-19 #' #' @section Function Introduced: #' `v0.10.0` (October 7, 2023) @@ -8803,7 +9489,7 @@ fmt_units <- function( #' #' @family data formatting functions #' @section Function ID: -#' 3-19 +#' 3-20 #' #' @section Function Introduced: #' **In Development** @@ -9208,7 +9894,7 @@ format_units_by_context <- function( #' #' @family data formatting functions #' @section Function ID: -#' 3-20 +#' 3-21 #' #' @section Function Introduced: #' `v0.9.0` (Mar 31, 2023) @@ -9807,7 +10493,7 @@ add_anchor_attr <- function( #' #' @family data formatting functions #' @section Function ID: -#' 3-21 +#' 3-22 #' #' @section Function Introduced: #' *In Development* @@ -10418,7 +11104,7 @@ generate_email_links <- function(email_address, anchor_attr, label_str) { #' #' @family data formatting functions #' @section Function ID: -#' 3-22 +#' 3-23 #' #' @section Function Introduced: #' `v0.9.0` (Mar 31, 2023) @@ -11050,7 +11736,7 @@ get_image_hw_ratio <- function(filepath) { #' #' @family data formatting functions #' @section Function ID: -#' 3-23 +#' 3-24 #' #' @section Function Introduced: #' `v0.9.0` (Mar 31, 2023) @@ -11489,7 +12175,7 @@ fmt_flag <- function( #' #' @family data formatting functions #' @section Function ID: -#' 3-24 +#' 3-25 #' #' @section Function Introduced: #' *In Development* @@ -12050,7 +12736,7 @@ fmt_country <- function( #' #' @family data formatting functions #' @section Function ID: -#' 3-25 +#' 3-26 #' #' @section Function Introduced: #' `v0.10.0` (October 7, 2023) @@ -12495,7 +13181,7 @@ fmt_icon <- function( #' #' @family data formatting functions #' @section Function ID: -#' 3-26 +#' 3-27 #' #' @section Function Introduced: #' `v0.2.0.5` (March 31, 2020) @@ -12712,7 +13398,7 @@ fmt_markdown <- function( #' #' @family data formatting functions #' @section Function ID: -#' 3-27 +#' 3-28 #' #' @section Function Introduced: #' `v0.2.0.5` (March 31, 2020) @@ -12974,7 +13660,7 @@ fmt_passthrough <- function( #' #' @family data formatting functions #' @section Function ID: -#' 3-28 +#' 3-29 #' #' @section Function Introduced: #' `v0.9.0` (Mar 31, 2023) @@ -13293,7 +13979,7 @@ fmt_auto <- function( #' #' @family data formatting functions #' @section Function ID: -#' 3-29 +#' 3-30 #' #' @section Function Introduced: #' `v0.2.0.5` (March 31, 2020) diff --git a/R/helpers.R b/R/helpers.R index 6afba022fa..73f6e5628c 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -1157,7 +1157,7 @@ stub <- function() { #' #' ```r #' sp500 |> -#' dplyr::filter(date >= "2015-01-05" & date <="2015-01-10") |> +#' dplyr::filter(date >= "2015-01-05" & date <= "2015-01-10") |> #' dplyr::select(-c(adj_close, volume, high, low)) |> #' gt() |> #' tab_header(title = "S&P 500") |> diff --git a/R/substitution.R b/R/substitution.R index edad6d3228..7f55313dd1 100644 --- a/R/substitution.R +++ b/R/substitution.R @@ -131,7 +131,7 @@ #' #' @family data formatting functions #' @section Function ID: -#' 3-30 +#' 3-31 #' #' @section Function Introduced: #' `v0.6.0` (May 24, 2022) @@ -336,7 +336,7 @@ fmt_missing <- function( #' #' @family data formatting functions #' @section Function ID: -#' 3-31 +#' 3-32 #' #' @section Function Introduced: #' `v0.6.0` (May 24, 2022) @@ -546,7 +546,7 @@ sub_zero <- function( #' #' @family data formatting functions #' @section Function ID: -#' 3-32 +#' 3-33 #' #' @section Function Introduced: #' `v0.6.0` (May 24, 2022) @@ -822,7 +822,7 @@ sub_small_vals <- function( #' #' @family data formatting functions #' @section Function ID: -#' 3-33 +#' 3-34 #' #' @section Function Introduced: #' `v0.6.0` (May 24, 2022) @@ -1127,7 +1127,7 @@ check_sub_fn_sign <- function(sign) { #' #' @family data formatting functions #' @section Function ID: -#' 3-34 +#' 3-35 #' #' @section Function Introduced: #' `v0.8.0` (November 16, 2022) diff --git a/R/sysdata.rda b/R/sysdata.rda index 8d70523278..4306354eb8 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/R/utils.R b/R/utils.R index b77d4a5c73..696967e901 100644 --- a/R/utils.R +++ b/R/utils.R @@ -222,13 +222,38 @@ time_formats <- function() { ) } +tf_formats <- function() { + + dplyr::tribble( + ~format_number, ~format_name, ~characters, ~idx, + "1", "true-false", NA, 1:2, + "2", "yes-no", NA, 3:4, + "3", "up-down", NA, 5:6, + "4", "check-mark", c("\U02714", "\U02718"), NA, + "5", "circles", c("\U025CF", "\U02B58"), NA, + "6", "squares", c("\U025A0", "\U025A1"), NA, + "7", "diamonds", c("\U025C6", "\U025C7"), NA, + "8", "arrows", c("\U02191", "\U02193"), NA, + "9", "triangles", c("\U025B2", "\U025BC"), NA, + "10", "triangles-lr", c("\U025B6", "\U025C0"), NA, + ) +} + +tf_formats_icons <- function() { + as.character(na.omit(tf_formats()[, "characters"][[1]])) +} + +tf_formats_text <- function() { + c("true-false", "yes-no", "up-down") +} + #' Transform a `date_style` to a `date_format` #' #' @noRd get_date_format <- function(date_style) { date_format_tbl <- date_formats() - date_format_num_range <- seq_len(nrow((date_format_tbl))) + date_format_num_range <- seq_len(nrow(date_format_tbl)) # In the rare instance that `date_style` consists of a character-based # number in the valid range of numbers, cast the value as a number @@ -282,7 +307,7 @@ get_date_format <- function(date_style) { get_time_format <- function(time_style) { time_format_tbl <- time_formats() - time_format_num_range <- seq_len(nrow((time_format_tbl))) + time_format_num_range <- seq_len(nrow(time_format_tbl)) # In the rare instance that `time_style` consists of a character-based # number in the valid range of numbers, cast the value as a number @@ -338,6 +363,69 @@ get_time_format <- function(time_style) { } } +#' Transform a `tf_style` to a vector of values +#' +#' @noRd +get_tf_vals <- function(tf_style, locale) { + + tf_format_tbl <- tf_formats() + tf_format_num_range <- seq_len(nrow(tf_format_tbl)) + + # In the rare instance that `tf_style` consists of a character-based + # number in the valid range of numbers, cast the value as a number + if ( + is.character(tf_style) && + tf_style %in% as.character(tf_format_num_range) + ) { + tf_style <- as.numeric(tf_style) + } + + # Stop function if a numeric `tf_style` value is invalid + if (is.numeric(tf_style)) { + + if (!(tf_style %in% tf_format_num_range)) { + cli::cli_abort(c( + "If using a numeric value for a `tf_style`, it must be + between `1` and `{nrow((tf_format_tbl))}`.", + "*" = "Use `info_tf_style()` for a useful visual reference." + )) + } + } + + # Stop function if a character-based `tf_style` value is invalid + if (is.character(tf_style)) { + + if (!(tf_style %in% tf_format_tbl$format_name)) { + cli::cli_abort(c( + "If using a `tf_style` name, it must be in the valid set.", + "*" = "Use `info_tf_style()` for a useful visual reference." + )) + } + + # Normalize `tf_style` to be a numeric index value + tf_style <- which(tf_format_tbl$format_name == tf_style) + } + + # Obtain the correct tf format directive + tf_format_tbl_i <- tf_format_tbl[tf_style, ] + + if (tf_format_tbl_i[["format_name"]] %in% tf_formats_text()) { + + # Obtain the row indices for the correct pair of complementary values + # from the `tf_words` table + tf_words_tbl_i <- tf_format_tbl_i[["idx"]][[1]] + + # Use the `locale` value to get the two localized strings + true_str <- tf_words[tf_words_tbl_i[1], ][[locale]] + false_str <- tf_words[tf_words_tbl_i[2], ][[locale]] + + return(c(true_str, false_str)) + + } else { + return(unlist(tf_format_tbl_i[["characters"]])) + } +} + #' Are string values 24 hour times? #' #' Determine whether string values are representative of ISO 8601 time parts diff --git a/R/utils_examples.R b/R/utils_examples.R index 7add9943d3..b0b3cd53a5 100644 --- a/R/utils_examples.R +++ b/R/utils_examples.R @@ -192,6 +192,8 @@ write_gt_examples_qmd_files <- function( "metro", "constants", "illness", + "reactions", + "photolysis", "rx_adsl", "rx_addv", "render_gt", diff --git a/data-raw/X13-tf_words.R b/data-raw/X13-tf_words.R new file mode 100644 index 0000000000..405f61273d --- /dev/null +++ b/data-raw/X13-tf_words.R @@ -0,0 +1,7 @@ +library(tidyverse) + +tf_words <- + readr::read_csv( + file = "data-raw/tf_words.csv", + col_types = cols(.default = col_character()) + ) diff --git a/data-raw/tf_words.csv b/data-raw/tf_words.csv new file mode 100644 index 0000000000..7c1a733622 --- /dev/null +++ b/data-raw/tf_words.csv @@ -0,0 +1,7 @@ +word,af,af-NA,agq,ak,am,ar,ar-AE,ar-BH,ar-DJ,ar-DZ,ar-EG,ar-EH,ar-ER,ar-IL,ar-IQ,ar-JO,ar-KM,ar-KW,ar-LB,ar-LY,ar-MA,ar-MR,ar-OM,ar-PS,ar-QA,ar-SA,ar-SD,ar-SO,ar-SS,ar-SY,ar-TD,ar-TN,ar-YE,as,asa,ast,az,az-Cyrl,az-Latn,bas,be,be-tarask,bem,bez,bg,bm,bn,bn-IN,bo,bo-IN,br,brx,bs,bs-Cyrl,bs-Latn,ca,ca-AD,ca-ES-valencia,ca-FR,ca-IT,ccp,ccp-IN,ce,ceb,cgg,chr,ckb,ckb-IR,cs,cy,da,da-GL,dav,de,de-AT,de-BE,de-CH,de-IT,de-LI,de-LU,dje,doi,dsb,dua,dyo,dz,ebu,ee,ee-TG,el,el-CY,en,en-001,en-150,en-AE,en-AG,en-AI,en-AS,en-AT,en-AU,en-BB,en-BE,en-BI,en-BM,en-BS,en-BW,en-BZ,en-CA,en-CC,en-CH,en-CK,en-CM,en-CX,en-CY,en-DE,en-DG,en-DK,en-DM,en-ER,en-FI,en-FJ,en-FK,en-FM,en-GB,en-GD,en-GG,en-GH,en-GI,en-GM,en-GU,en-GY,en-HK,en-IE,en-IL,en-IM,en-IN,en-IO,en-JE,en-JM,en-KE,en-KI,en-KN,en-KY,en-LC,en-LR,en-LS,en-MG,en-MH,en-MO,en-MP,en-MS,en-MT,en-MU,en-MV,en-MW,en-MY,en-NA,en-NF,en-NG,en-NL,en-NR,en-NU,en-NZ,en-PG,en-PH,en-PK,en-PN,en-PR,en-PW,en-RW,en-SB,en-SC,en-SD,en-SE,en-SG,en-SH,en-SI,en-SL,en-SS,en-SX,en-SZ,en-TC,en-TK,en-TO,en-TT,en-TV,en-TZ,en-UG,en-UM,en-VC,en-VG,en-VI,en-VU,en-WS,en-ZA,en-ZM,en-ZW,eo,es,es-419,es-AR,es-BO,es-BR,es-BZ,es-CL,es-CO,es-CR,es-CU,es-DO,es-EA,es-EC,es-GQ,es-GT,es-HN,es-IC,es-MX,es-NI,es-PA,es-PE,es-PH,es-PR,es-PY,es-SV,es-US,es-UY,es-VE,et,eu,ewo,fa,fa-AF,ff,ff-Adlm,ff-Adlm-BF,ff-Adlm-CM,ff-Adlm-GH,ff-Adlm-GM,ff-Adlm-GW,ff-Adlm-LR,ff-Adlm-MR,ff-Adlm-NE,ff-Adlm-NG,ff-Adlm-SL,ff-Adlm-SN,ff-Latn,ff-Latn-BF,ff-Latn-CM,ff-Latn-GH,ff-Latn-GM,ff-Latn-GN,ff-Latn-GW,ff-Latn-LR,ff-Latn-MR,ff-Latn-NE,ff-Latn-NG,ff-Latn-SL,fi,fil,fo,fo-DK,fr,fr-BE,fr-BF,fr-BI,fr-BJ,fr-BL,fr-CA,fr-CD,fr-CF,fr-CG,fr-CH,fr-CI,fr-CM,fr-DJ,fr-DZ,fr-GA,fr-GF,fr-GN,fr-GP,fr-GQ,fr-HT,fr-KM,fr-LU,fr-MA,fr-MC,fr-MF,fr-MG,fr-ML,fr-MQ,fr-MR,fr-MU,fr-NC,fr-NE,fr-PF,fr-PM,fr-RE,fr-RW,fr-SC,fr-SN,fr-SY,fr-TD,fr-TG,fr-TN,fr-VU,fr-WF,fr-YT,fur,fy,ga,ga-GB,gd,gl,gsw,gsw-FR,gsw-LI,gu,guz,gv,ha,ha-GH,ha-NE,haw,he,hi,hi-Latn,hr,hr-BA,hsb,hu,hy,ia,id,ig,ii,is,it,it-CH,it-SM,it-VA,ja,jgo,jmc,jv,ka,kab,kam,kde,kea,kgp,khq,ki,kk,kkj,kl,kln,km,kn,ko,ko-KP,kok,ks,ks-Arab,ks-Deva,ksb,ksf,ksh,ku,kw,ky,lag,lb,lg,lkt,ln,ln-AO,ln-CF,ln-CG,lo,lrc,lrc-IQ,lt,lu,luo,luy,lv,mai,mas,mas-TZ,mer,mfe,mg,mgh,mgo,mi,mk,ml,mn,mni,mni-Beng,mr,ms,ms-BN,ms-ID,ms-SG,mt,mua,my,mzn,naq,nb,nb-SJ,nd,nds,nds-NL,ne,ne-IN,nl,nl-AW,nl-BE,nl-BQ,nl-CW,nl-SR,nl-SX,nmg,nn,nnh,no,nus,nyn,om,om-KE,or,os,os-RU,pa,pa-Arab,pa-Guru,pcm,pl,ps,ps-PK,pt,pt-AO,pt-CH,pt-CV,pt-GQ,pt-GW,pt-LU,pt-MO,pt-MZ,pt-PT,pt-ST,pt-TL,qu,qu-BO,qu-EC,rm,rn,ro,ro-MD,rof,ru,ru-BY,ru-KG,ru-KZ,ru-MD,ru-UA,rw,rwk,sa,sah,saq,sat,sat-Olck,sbp,sc,sd,sd-Arab,sd-Deva,se,se-FI,se-SE,seh,ses,sg,shi,shi-Latn,shi-Tfng,si,sk,sl,smn,sn,so,so-DJ,so-ET,so-KE,sq,sq-MK,sq-XK,sr,sr-Cyrl,sr-Cyrl-BA,sr-Cyrl-ME,sr-Cyrl-XK,sr-Latn,sr-Latn-BA,sr-Latn-ME,sr-Latn-XK,su,su-Latn,sv,sv-AX,sv-FI,sw,sw-CD,sw-KE,sw-UG,ta,ta-LK,ta-MY,ta-SG,te,teo,teo-KE,tg,th,ti,ti-ER,tk,to,tr,tr-CY,tt,twq,tzm,ug,uk,und,ur,ur-IN,uz,uz-Arab,uz-Cyrl,uz-Latn,vai,vai-Latn,vai-Vaii,vi,vun,wae,wo,xh,xog,yav,yi,yo,yo-BJ,yrl,yrl-CO,yrl-VE,yue,yue-Hans,yue-Hant,zgh,zh,zh-Hans,zh-Hans-HK,zh-Hans-MO,zh-Hans-SG,zh-Hant,zh-Hant-HK,zh-Hant-MO,zu +true,waar,waar,mbu,benkum,እውነት ነው።,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,حقيقي,সঁচা,bwe,verdaderu,doğrudur,true,doğrudur,true,праўда,праўда,kwati,true,вярно,tògò,সত্য,সত্য,true,true,gwir,true,istina,true,istina,cert,cert,cert,cert,cert,true,true,дийцар,tinuod,kweli,ᏗᎳᏂᏂ,راستە,راستە,pravda,gwir,sand,sand,ũkweli,wahr,wahr,wahr,wahr,wahr,wahr,wahr,koy,true,prawdziwy,mɛ́nɔ́,ngaan,བདེན་པ་,ũtũ,nyateƒe,nyateƒe,αληθής,αληθής,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,vera,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,verdadero,tõsi,egia,éfé,درست,درست,ndiyam,ߢߍߺߣߍ,ߢߍߺߣߍ,ߢߍߺߣߍ,ߢߍߺߣߍ,ߢߍߺߣߍ,ߢߍߺߣߍ,ߢߍߺߣߍ,ߢߍߺߣߍ,ߢߍߺߣߍ,ߢߍߺߣߍ,ߢߍߺߣߍ,ߢߍߺߣߍ,ndiyam,ndiyam,ndiyam,ndiyam,ndiyam,ndiyam,ndiyam,ndiyam,ndiyam,ndiyam,ndiyam,ndiyam,totta,totoo,sannur,sannur,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vrai,vere,wier,fíor,fíor,fìor,verdadeiro,wahr,wahr,wahr,સાચું,enchore,smooinaght,gaskiya,gaskiya,gaskiya,'oia'i'o,נכון,सत्य,saty,istina,istina,prawdziwy,igaz,ճիշտ,ver,benar,okenye,ꆏꉚ,satt,vero,vero,vero,vero,真実,ndôô,ndyo,bener,ჭეშმარიტი,ayen,oo,nde,sim,true,ene,ithu,жақсы,true,nde,true,ពិត,ನಿಜ,진실,진실,खरी,سچ,سچ,सच,ndiyo,éem,wah,rast,yth,туура,lete,wouer,kituufu,hau,solo,solo,solo,solo,ຄວາມຈິງ,ہەڵە ,ہەڵە ,tiesa,bika,duto,ndi,taisnība,true,yesu,yesu,tia,vre,tsara,aho,ǹa,pono,точно,ശരി,үнэн,নাংবাসা,নাংবাসা,खरे,benar,benar,benar,benar,veru,afa,အမှန်,راست,true,sann,sann,kuyisiko,wohr,woar,सत्य,सत्य,waar,waar,waar,waar,waar,waar,waar,vù,sann,true,sann,kek,eego,dhugaadha,dhugaadha,ସତ |,æрæ,æрæ,ਸਹੀ,سچ,ਸਹੀ,tru,prawda,ریښتیا,ریښتیا,verdadeiro,verdadeiro,verdadeiro,verdadeiro,verdadeiro,verdadeiro,verdadeiro,verdadeiro,verdadeiro,verdadeiro,verdadeiro,verdadeiro,chiqapmi,chiqapmi,chiqapmi,ver,vyinshi,adevărată,adevărată,eego,правда,правда,правда,правда,правда,правда,cyane,iyo,सत्यम्,сөп,ler,true,true,iliyo,beru,سچ,سچ,true,dahji,dahje,dahje,true,iyo,tî,ⵉⵙⴷⴰⵏ,ih,ⵉⵙⴷⴰⵏ,ඇත්ත,pravdivá,res,važžâd,zvawaida,run,run,run,run,e vërtetë,e vërtetë,e vërtetë,истина,истина,истина,истина,истина,istina,istina,istina,istina,leres,leres,sant,sant,sant,kweli,kweli,kweli,kweli,உண்மை,உண்மை,உண்மை,உண்மை,నిజం,ono,ono,ҳақиқӣ,จริง,ሓቂ እዩ,ሓቂ እዩ,dogry,ʻoatu,doğru,doğru,дөрес,true,ih,راست,правда,true,سچ,سچ,haqiqat,حقيقي,ҳақиқий,haqiqat,ꕙꔤꕭ,ɓɛ̃ɛ̃,ꕙꔤꕭ,đúng,true,true,ñaam,yinyani,true,tôô,ריכטיג,otitọ,otitọ,true,true,true,實,真,實,true,正確,正確,正確,正確,正確,真实,真实,真实,iqiniso +false,onwaar,onwaar,vum,safoa,የውሸት,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,خطأ شنيع,মিছা,mù,falsu,yalan,false,yalan,false,ілжывы,ілжывы,pali,false,невярно,kɔnɔ,মিথ্যা,মিথ্যা,false,false,gouestlet,false,netačno,false,netačno,fals,fals,fals,fals,fals,false,false,ноттар,sala,bulungi,ᎧᏂᏂ,هەقیقی,هەقیقی,nepravda,ffug,falsk,falsk,ivi,falsch,falsch,falsch,falsch,falsch,falsch,falsch,kun,false,fałszywy,díá,am,མེན་པ་,cia,alakpa,alakpa,ψευδής,ψευδής,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,malvera,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,false,faltsua,ébɔ́,غلط,غلط,alaa,ߟߌ߲ߕߌ߲,ߟߌ߲ߕߌ߲,ߟߌ߲ߕߌ߲,ߟߌ߲ߕߌ߲,ߟߌ߲ߕߌ߲,ߟߌ߲ߕߌ߲,ߟߌ߲ߕߌ߲,ߟߌ߲ߕߌ߲,ߟߌ߲ߕߌ߲,ߟߌ߲ߕߌ߲,ߟߌ߲ߕߌ߲,ߟߌ߲ߕߌ߲,alaa,alaa,alaa,alaa,alaa,alaa,alaa,alaa,alaa,alaa,alaa,alaa,false,mali,ósannur,ósannur,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,faux,fals,falsk,bréagach,bréagach,meallta,falso,falsch,falsch,falsch,ખોટું,enchoro,brishey,ƙarya,ƙarya,ƙarya,wahahe'e,לא נכון,असत्य,galat,lažna,lažna,fałszywy,hamis,կեղծ,fals,salah,okwa,ꉍꆏ,ósatt,falso,falso,falso,falso,間違い,wuô,siyo,palsu,ყალბი,ur,sya,hae,falso,false,ala,cio,жалған,false,tè,false,មិនពិត,ಸುಳ್ಳು,거짓,거짓,खोटी,غلط,غلط, ग़लत,siyo,éjòò,fing,derewîn,le,жалган,lise,falsch,bulimba,caŋ,lokuta,lokuta,lokuta,lokuta,ບໍ່ຖືກຕ້ອງ,نەچ,نەچ,klaidinga,nyonso,pek,si,nepatiesa,false,eng'o,eng'o,ti,fo,tsy marina,mina,ǹgǔ,he,неточно,തെറ്റ്,худал,নাংবাসা নাই,নাংবাসা নাই,असत्य,palsu,palsu,palsu,palsu,falz,aŋɡwa,အတုအယောင်,دروغ,false,usann,usann,akuyikiso,falsch,nait woar,गलत,गलत,onwaar,onwaar,onwaar,onwaar,onwaar,onwaar,onwaar,vò,usann,false,usann,cïn,nahi,soba,soba,ମିଥ୍ୟା |,нæй,нæй,ਗਲਤ,جھوٹ,ਗਲਤ,falz,fałsz,غلط,غلط,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,falso,llulla,llulla,llulla,fals,nta nyinshi,fals,fals,hanaa,ложь,ложь,ложь,ложь,ложь,ложь,oya,siyo,मिथ्या,тоҕо,loru,false,false,sikweli,falsu,غلط,غلط,false,ii,ii,ii,false,ala,mâ,ⵏⵓⴰ,ur,ⵏⵓⴰ,අසත්ය,nepravda,neresnična,eai,chokwadi,been,been,been,been,i rremë,i rremë,i rremë,лажно,лажно,лажно,лажно,лажно,lažno,lažno,lažno,lažno,palsu,palsu,falskt,falskt,falskt,uongo,uongo,uongo,uongo,பொய்,பொய்,பொய்,பொய்,తప్పు,oyo,oyo,бардурӯғ,เท็จ,ሓሶት እዩ,ሓሶት እዩ,ýalan,ʻikai,yanlış,yanlış,ялган,false,ur,يالغان,неправда,false,غلط,غلط,yolg'on,غلط,нотўғри,yolg'on,ꔎꔒ,gaa,ꔎꔒ,sai,false,false,dëgg na,bubuxoki,false,tɛɛ,פאַלש,eke,eke,false,false,false,假,假,假,false,假,假,假,假,假,假,假,假,amanga +yes,ja,ja,òo,yiw,አዎ,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,نعم,হয়,Iyee,sí,bəli,yes,bəli,ŋ̀ŋ̂,так,так,ee,Eeh,да,ɔwɔ,হ্যাঁ,হ্যাঁ,ཡིན,ཡིན,ya,नंगौ,da,да,da,sí,sí,sí,sí,sí,𑄃𑄳,𑄃𑄳,ай,oo,ye,ᎥᎥ,ەڵێ,ەڵێ,ano,ydw,ja,ja,eego,ja,ja,ja,ja,ja,ja,ja,ee,हां,jo,ée,waaw,ཨེ་ཨེན་,ee,ẽ,ẽ,ναι,ναι,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,yes,jes,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,sí,jah,bai,éyé,بله,بله,ey,𞤢𞤱𞤢,𞤢𞤱𞤢,𞤢𞤱𞤢,𞤢𞤱𞤢,𞤢𞤱𞤢,𞤢𞤱𞤢,𞤢𞤱𞤢,𞤢𞤱𞤢,𞤢𞤱𞤢,𞤢𞤱𞤢,𞤢𞤱𞤢,𞤢𞤱𞤢,ey,ey,ey,ey,ey,ey,ey,ey,ey,ey,ey,ey,kyllä,oo,ja,ja,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,oui,sì,ja,tá,tá,tha,si,ja,ja,ja,હા,ewe,v'ea,eh,eh,eh,'ae,כן,हाँ,haan,da,da,jo,igen,այո,si,ya,eewo,ꀕꉓ,já,sì,sì,sì,sì,はい,éé,ndiyo,ya,კი,ih,ndi,ee,sim,hỹ,ewa,ee,иә,yes,éé,wei,បាទ,ಹೌದು,예,예,हय,آ,آ,आ,ndiyo,éewó,jo,erê,yeh,ээ,ewe,jo,yee,hau,nde,nde,nde,nde,ແມ່ນ,هأری,هأری,taip,eyo,adhi,ee,jā,हं,eeyo,eeyo,ee,wi,eny,ewa,éé,āe,да,ഉവ്വ്,тийм,য়েস,য়েস,होय,ya,ya,ya,ya,iva,eeh,ဟုတ်တယ်,آره,Îi,ja,ja,yebo,joa,joa,हो,हो,ja,ja,ja,ja,ja,ja,ja,éé,ja,yes,ja,eey,yebo,eeyyee,eeyyee,ହଁ,æй,æй,ਹਾਂ,ہاں,ਹਾਂ,yes,tak,هو,هو,sim,sim,sim,sim,sim,sim,sim,sim,sim,sim,sim,sim,arí,arí,arí,tge,ego,da,da,eego,да,да,да,да,да,да,yego,ndiyo,आम्,сөп,eey,ᱦᱚ,ᱦᱚ,ndiyo,si,ها,ها,हा,juo,juo,juo,ande,iyo,êe,ⵢⵢⵉⵀ,ih,ⵢⵢⵉⵀ,ඔව්,áno,da,juo,ewe,haa,haa,haa,haa,po,po,po,да,да,да,да,да,da,da,da,da,enya,enya,ja,ja,ja,ndio,ndio,ndio,ndio,ஆம்,ஆம்,ஆம்,ஆம்,అవును,eda,eda,ҳа,ใช่,እወ,እወ,hawa,ʻio,evet,evet,әйе,ayyo,ih,ھەئە,так,yes,ہاں,ہاں,ha,ھا,ҳа,ha,ꕪꕴ,oo,ꕪꕴ,có,haya,ja,waaw,ewe,ye,éé,יאָ,bẹẹni,bẹẹni,eẽ,eẽ,eẽ,係,系,係,ⵢⵢⵉⵀ,确定,确定,确定,确定,确定,是,是,是,yebo +no,nee,nee,hǎe,daabi,አይ,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,لا,নহয়,hai,non,yox,no,yox,tɔ̀,не,не,awe,Sio ewo,не,ayi,না,না,མིན།,མིན།,ket,नङा,ne,не,ne,no,no,no,no,no,𑄚,𑄚,воьрта,dili,nedda,ᎥᏝ,ەخێر,ەخێر,ne,na,nej,nej,eeya,nein,nein,nein,nein,nein,nein,nein,a'a,नेईं,njy,oó,alu,མེ་མེན་,a-a,ao,ao,όχι,όχι,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,ne,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,ei,ez,éhé,نه,نه,alaa,𞤮𞥅𞤮,𞤮𞥅𞤮,𞤮𞥅𞤮,𞤮𞥅𞤮,𞤮𞥅𞤮,𞤮𞥅𞤮,𞤮𞥅𞤮,𞤮𞥅𞤮,𞤮𞥅𞤮,𞤮𞥅𞤮,𞤮𞥅𞤮,𞤮𞥅𞤮,alaa,alaa,alaa,alaa,alaa,alaa,alaa,alaa,alaa,alaa,alaa,alaa,ei,hindi,nei,nei,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,non,no,nee,níl,níl,chan eil,non,näi,näi,näi,ના,agwaki,cha nel,aʼa,aʼa,aʼa,'a'ole,לא,नहीं,nahin,ne,ne,njy,nem,ոչ,no,tidak,mgbe,ꀃꋊ,nei,no,no,no,no,いいえ,tèè,hapana,ora,არა,ara,sya,hae,não,tũ,ala,a-a,жоқ,no,a,achicha,ទេ។,ಇಲ್ಲ,아니요,아니요,ना,نَہ,نَہ,न,hapana,éjòò,nee,na,na,жок,ene,nee,nedda,caŋ,te,te,te,te,ບໍ່,نه,نه,ne,to,en,iyo,nē,नहि,eng'o,eng'o,a-a,non,tsia,ayi,áá,kāo,не,അല്ല,үгүй,নো,নো,नाही,tidak,tidak,tidak,tidak,le,aŋɡwa,မဟုတ်ဘူး,نه,Hî-î,nei,nei,cha,nee,nee,होइन,होइन,nee,nee,nee,nee,nee,nee,nee,mba,nei,no,nei,baai,nahi,lakki,lakki,ନା,нæй,нæй,ਨਹੀਂ,نہيں,ਨਹੀਂ,no,nie,نه,نه,não,não,não,não,não,não,não,não,não,não,não,não,manam,manam,manam,betg,oya,nu,nu,hanaa,нет,нет,нет,нет,нет,нет,oya,siyo,न,суох,aiy,ᱵᱟᱝ,ᱵᱟᱝ,hapana,no,نه,نه,न,ii,ii,ii,nkhabe,ala,tî mâ,ⵓⵀⵓ,ur,ⵓⵀⵓ,නැත,nie,ne,eai,aye,maya,maya,maya,maya,jo,jo,jo,не,не,не,не,не,ne,ne,ne,ne,teu,teu,nej,nej,nej,hapana,hapana,hapana,hapana,இல்லை,இல்லை,இல்லை,இல்லை,వద్దు,enaka,enaka,не,ไม่ใช่,ኣይፋልን,ኣይፋልን,ýok,ʻikai,hayir,hayır,юк,kala,ur,ياق,ні,no,نہیں,نہیں,yo‘q,يوق,йўқ,yo‘q,ꔉꔒ,gɛ̃ɛ̃,ꔉꔒ,không,ote,nei,déedet,hayi,be,néé,ניין,rara,rara,ũbaá,ũbaá,ũbaá,唔係,唔系,唔係,ⵓⵀⵓ,否定,否定,否定,否定,否定,否,否,否,cha +up,op,op,ngweh,bepɔw,ወደ ላይ,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,أعلى,ওপৰলৈ,nkɔ,arriba,yuxarı,up,yuxarı,up,уверх,уверх,ku mwamba,up,нагоре,nà,উপরে,উপরে,up,up,war-lerc'h,up,gore,up,gore,amunt,amunt,amunt,amunt,amunt,up,up,хьо,taas,okwerali,ᎠᏒᏴᎢ,سەر,سەر,nahoru,i fyny,op,op,kũsiri,oben,oben,oben,oben,oben,oben,oben,koko,up,hórnje,émí,ndox,ཡིན་ཆེན་,kũrũ,dzi,dzi,επάνω,επάνω,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,up,supren,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,arriba,üles,gora,ébú,الا,الا,yontuɗo,ߡߊ߬ߟߊ,ߡߊ߬ߟߊ,ߡߊ߬ߟߊ,ߡߊ߬ߟߊ,ߡߊ߬ߟߊ,ߡߊ߬ߟߊ,ߡߊ߬ߟߊ,ߡߊ߬ߟߊ,ߡߊ߬ߟߊ,ߡߊ߬ߟߊ,ߡߊ߬ߟߊ,ߡߊ߬ߟߊ,yontuɗo,yontuɗo,yontuɗo,yontuɗo,yontuɗo,yontuɗo,yontuɗo,yontuɗo,yontuɗo,yontuɗo,yontuɗo,yontuɗo,ylös,taas,upp,upp,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,haut,sù,omheech,suas,suas,suas,arriba,oben,oben,oben,ઉપર,eneba,foast,sama,sama,sama,pi'i,למעלה,ऊपर,oopar,gore,gore,górjew,felfelé,վերև,su,ke atas,n'elu,ꁆꉈ,upp,su,su,su,su,上です,nvûû,juu,munggah,ზევით,uɣerbaz,mūtini,wambo,riba,up,maŋa,ruo,жоғары,up,wɛ́,up,ឡើង,ಮೇಲಕ್ಕೆ,위쪽,위쪽,वयर,ووتھ,ووتھ,उपर,juu,émì,erop,jor,uw,жогору,lala,erop,waggulu,iŋyaŋ,kolóngó,kolóngó,kolóngó,kolóngó,ຂຶ້ນ,سەر,سەر,aukštyn,mulongesha,chieng',kuvula,uz augšu,up,oloip,oloip,kuuma,monte,ambony,kulaho,kíkí,whakarunga,горе,മുകളിലേക്ക്,дээш,মৈয়েবা,মৈয়েবা,वर,atas,atas,atas,atas,'l fuq,kɔm,တက်,بالا,up,opp,opp,phezulu,na'boben,noar boven,माथि,माथि,omhoog,omhoog,omhoog,omhoog,omhoog,omhoog,omhoog,ndzù,opp,up,opp,keek,okuva,ol,ol,ଉପରକୁ |,адæлы,адæлы,ਉੱਪਰ,اوتے,ਉੱਪਰ,up,w górę,پورته,پورته,para cima,para cima,para cima,para cima,para cima,para cima,para cima,para cima,para cima,para cima,para cima,para cima,wichayman,wichayman,wichayman,sù,kera,sus,sus,juu,вверх,вверх,вверх,вверх,вверх,вверх,hejuru,juu,उपरि,уҥа,ng'oto,up,up,juu,susu,مٿي,مٿي,up,buohcci,buohcci,buohcci,up,sanga,kû,ⵉⵍⵍⴰ,illa,ⵉⵍⵍⴰ,ඉහළට,hore,gor,yläs,pamusoro,kor,kor,kor,kor,lart,lart,lart,горе,горе,горе,горе,горе,gore,gore,gore,gore,ka luhur,ka luhur,upp,upp,upp,juu,juu,juu,juu,மேலே,மேலே,மேலே,மேலே,పైకి,tiyo,tiyo,боло,ขึ้น,ሓፍ,ሓፍ,ýokary,he ʻolunga,yukarı,yukarı,өскә,up,tawwurt,يۇقىرى,вгору,up,اوپر,اوپر,yuqori,يوقارى,юқори,yuqori,ꔛꕚ,diɛ,ꔛꕚ,lên,up,up,ñaari,phezulu,up,hèè,אַרויף,soke,soke,up,up,up,向上,向上,向上,up,向上,向上,向上,向上,向上,向上,向上,向上,phezulu +down,af,af,nde,bepɔ,ወደ ታች,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,أسفل,তললৈ,ke,abajo,aşağı,down,aşağı,down,уніз,уніз,ku chalo,down,надолу,kònò,নিচে,নিচে,down,down,war-lec'h,down,dolje,down,dolje,avall,avall,avall,avall,avall,down,down,буьхьа,ubos,okweri,ᎠᏂᏴᎢ,خوار,خوار,dolů,i lawr,ned,ned,kũtswa,unten,unten,unten,unten,unten,unten,unten,kaa,down,dóla,éyá,fuut,མེན་ཆེན་,kũma,anyime,anyime,κάτω,κάτω,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,malsupren,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,abajo,alla,behera,ékó,پایین,پایین,hakkunde,ߞߊ߲ߠߊ߲,ߞߊ߲ߠߊ߲,ߞߊ߲ߠߊ߲,ߞߊ߲ߠߊ߲,ߞߊ߲ߠߊ߲,ߞߊ߲ߠߊ߲,ߞߊ߲ߠߊ߲,ߞߊ߲ߠߊ߲,ߞߊ߲ߠߊ߲,ߞߊ߲ߠߊ߲,ߞߊ߲ߠߊ߲,ߞߊ߲ߠߊ߲,hakkunde,hakkunde,hakkunde,hakkunde,hakkunde,hakkunde,hakkunde,hakkunde,hakkunde,hakkunde,hakkunde,hakkunde,alas,baba,niður,niður,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,bas,jù,del,síos,síos,sìos,abaixo,unten,unten,unten,નીચે,enura,sheese,kasa,kasa,kasa,i lalo,למטה,नीचे,neeche,dolje,dolje,dółoj,lefelé,ներքև,juso,ke bawah,n'aka,ꀎꋌ,niður,giù,giù,giù,giù,下です,nvɔ̂ɔ̂,chini,mudhun,ქვემოთ,iserdas,mūkatho,chini,baixu,down,kono,thutha,төмен,down,bó,down,ចុះក្រោម,ಕೆಳಗೆ,아래,아래,सकयल,تھٕلا,تھٕلا,नीचे,chini,éfú,eraf,jêr,isel,төмөн,lebo,erof,wansi,pejútaŋ,kobútá,kobútá,kobútá,kobútá,ລົງ,خوار,خوار,žemyn,mulongeshi,giya,kumala,uz leju,down,olok,olok,kunya,desann,ambany,kuwala,súm,whakararo,надолу,താഴേക്ക്,доош,লুইবা,লুইবা,खाली,ke bawah,ke bawah,ke bawah,ke bawah,isfel,baa,ဆင်း,پایین,down,ned,ned,pansi,na'ben,noar beneden,तल,तल,naar,naar,naar,naar,naar,naar,naar,ndzò,ned,down,ned,bïr,okugwa,gadi bu’aadha,gadi bu’aadha,ତଳକୁ |,бæлы,бæлы,ਹੇਠਾਂ,تے,ਹੇਠਾਂ,down,w dół,ښکته,ښکته,para baixo,para baixo,para baixo,para baixo,para baixo,para baixo,para baixo,para baixo,para baixo,para baixo,para baixo,para baixo,urayman,urayman,urayman,giù,kumwe,în jos,în jos,chini,вниз,вниз,вниз,вниз,вниз,вниз,hasi,chini,अधः,төл,ng'op,down,down,chini,giù,هيٺ,هيٺ,down,alccesis,alccesis,alccesis,down,saba,nyê,ⵉⵙⴼⴻⵍ,isfel,ⵉⵙⴼⴻⵍ,පහළට,dole,navzdol,allos,pasi,hoos,hoos,hoos,hoos,poshtë,poshtë,poshtë,доле,доле,доле,доле,доле,dole,dole,dole,dole,handap,handap,ner,ner,ner,chini,chini,chini,chini,கீழே,கீழே,கீழே,கீழே,క్రిందికి,ecek,ecek,поён,ลง,ታሕቲ,ታሕቲ,aşak,he lalo,aşağı,aşağı,аста,down,tasenselt,تۆۋەن,вниз,down,نیچے,نیچے,past,پست,паст,past,ꖸꕆ,gben,ꖸꕆ,xuống,down,down,bës buñ,phantsi,down,vɛɛ,אַראָפּ,isalẹ,isalẹ,down,down,down,降落,降落,降落,down,降落,降落,降落,降落,降落,降落,降落,降落,phansi \ No newline at end of file diff --git a/data-raw/zz_process_datasets_ext.R b/data-raw/zz_process_datasets_ext.R index 897a8b76de..003a6f443e 100644 --- a/data-raw/zz_process_datasets_ext.R +++ b/data-raw/zz_process_datasets_ext.R @@ -12,12 +12,13 @@ source("data-raw/X09-styles_colors_params.R") source("data-raw/X10-spelled_num.R") source("data-raw/X11-flags.R") source("data-raw/X12-country_names.R") +source("data-raw/X13-tf_words.R") # Create internal datasets (`sysdata.rda`) usethis::use_data( currencies, currency_symbols, locales, default_locales, palettes_strips, google_font_tbl, google_styles_tbl, google_axes_tbl, css_colors, fractions, durations, styles_colors_params, - spelled_num, flag_tbl, country_names, + spelled_num, flag_tbl, country_names, tf_words, internal = TRUE, overwrite = TRUE ) diff --git a/images/man_fmt_tf_1.png b/images/man_fmt_tf_1.png new file mode 100644 index 0000000000..4a7d395870 Binary files /dev/null and b/images/man_fmt_tf_1.png differ diff --git a/images/man_fmt_tf_2.png b/images/man_fmt_tf_2.png new file mode 100644 index 0000000000..9b58051c7f Binary files /dev/null and b/images/man_fmt_tf_2.png differ diff --git a/images/man_fmt_tf_3.png b/images/man_fmt_tf_3.png new file mode 100644 index 0000000000..7a32fe54a4 Binary files /dev/null and b/images/man_fmt_tf_3.png differ diff --git a/images/man_fmt_tf_4.png b/images/man_fmt_tf_4.png new file mode 100644 index 0000000000..609b46395e Binary files /dev/null and b/images/man_fmt_tf_4.png differ diff --git a/man/cells_title.Rd b/man/cells_title.Rd index 13389616b3..d0c6ffcb5b 100644 --- a/man/cells_title.Rd +++ b/man/cells_title.Rd @@ -75,7 +75,7 @@ header with a title, and then add a footnote to the title with \code{\link[=tab_footnote]{tab_footnote()}} and \code{cells_title()} (in \code{locations}). \if{html}{\out{
}}\preformatted{sp500 |> - dplyr::filter(date >= "2015-01-05" & date <="2015-01-10") |> + dplyr::filter(date >= "2015-01-05" & date <= "2015-01-10") |> dplyr::select(-c(adj_close, volume, high, low)) |> gt() |> tab_header(title = "S&P 500") |> diff --git a/man/data_color.Rd b/man/data_color.Rd index 1ef5998ec6..7436246403 100644 --- a/man/data_color.Rd +++ b/man/data_color.Rd @@ -693,7 +693,7 @@ gray cells for the missing values (we also removed the \code{"NA"} text with \section{Function ID}{ -3-35 +3-36 } \section{Function Introduced}{ @@ -729,6 +729,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt.Rd b/man/fmt.Rd index ea6f5930cd..311b81a50e 100644 --- a/man/fmt.Rd +++ b/man/fmt.Rd @@ -139,7 +139,7 @@ the column (\code{x}), multiply them by 1000, and exclose them in single quotes. \section{Function ID}{ -3-29 +3-30 } \section{Function Introduced}{ @@ -175,6 +175,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_auto.Rd b/man/fmt_auto.Rd index efac085640..d2a3884489 100644 --- a/man/fmt_auto.Rd +++ b/man/fmt_auto.Rd @@ -164,7 +164,7 @@ scientific notation. This is done by using the \code{lg_num_pref = "suf"} option \section{Function ID}{ -3-28 +3-29 } \section{Function Introduced}{ @@ -200,6 +200,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_bins.Rd b/man/fmt_bins.Rd index 39b7b1b7b3..17f412e56d 100644 --- a/man/fmt_bins.Rd +++ b/man/fmt_bins.Rd @@ -227,6 +227,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_bytes.Rd b/man/fmt_bytes.Rd index ac78129e7e..b822f24666 100644 --- a/man/fmt_bytes.Rd +++ b/man/fmt_bytes.Rd @@ -354,6 +354,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_chem.Rd b/man/fmt_chem.Rd index 0762c432af..a96ba9d4c1 100644 --- a/man/fmt_chem.Rd +++ b/man/fmt_chem.Rd @@ -216,7 +216,7 @@ compound names via the \code{\link[=cols_merge]{cols_merge()}} function. \section{Function ID}{ -3-19 +3-20 } \section{Function Introduced}{ @@ -252,6 +252,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_country.Rd b/man/fmt_country.Rd index 77d2cde4e3..cecf34338e 100644 --- a/man/fmt_country.Rd +++ b/man/fmt_country.Rd @@ -271,7 +271,7 @@ different \code{locale} values in separate calls of \code{fmt_country()}. \section{Function ID}{ -3-24 +3-25 } \section{Function Introduced}{ @@ -307,6 +307,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_currency.Rd b/man/fmt_currency.Rd index 9267459a2a..83feada0f3 100644 --- a/man/fmt_currency.Rd +++ b/man/fmt_currency.Rd @@ -563,6 +563,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_date.Rd b/man/fmt_date.Rd index 108014645b..38c7daef25 100644 --- a/man/fmt_date.Rd +++ b/man/fmt_date.Rd @@ -335,6 +335,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_datetime.Rd b/man/fmt_datetime.Rd index f556f4e600..f70a69a108 100644 --- a/man/fmt_datetime.Rd +++ b/man/fmt_datetime.Rd @@ -1008,6 +1008,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_duration.Rd b/man/fmt_duration.Rd index 19f48f1f21..6a785daa86 100644 --- a/man/fmt_duration.Rd +++ b/man/fmt_duration.Rd @@ -337,6 +337,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_email.Rd b/man/fmt_email.Rd index 543119635e..f38316452c 100644 --- a/man/fmt_email.Rd +++ b/man/fmt_email.Rd @@ -199,7 +199,7 @@ closed set. \section{Function ID}{ -3-21 +3-22 } \section{Function Introduced}{ @@ -235,6 +235,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_engineering.Rd b/man/fmt_engineering.Rd index 388962d6d5..1f1642badc 100644 --- a/man/fmt_engineering.Rd +++ b/man/fmt_engineering.Rd @@ -326,6 +326,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_flag.Rd b/man/fmt_flag.Rd index 7cc3cd051f..11447b9f98 100644 --- a/man/fmt_flag.Rd +++ b/man/fmt_flag.Rd @@ -306,7 +306,7 @@ tooltip text showing the name of the country. \section{Function ID}{ -3-23 +3-24 } \section{Function Introduced}{ @@ -342,6 +342,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_fraction.Rd b/man/fmt_fraction.Rd index fd3117965b..cec288be5c 100644 --- a/man/fmt_fraction.Rd +++ b/man/fmt_fraction.Rd @@ -358,6 +358,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_icon.Rd b/man/fmt_icon.Rd index 9987d52035..3ac9c7102f 100644 --- a/man/fmt_icon.Rd +++ b/man/fmt_icon.Rd @@ -433,7 +433,7 @@ each icon. \section{Function ID}{ -3-25 +3-26 } \section{Function Introduced}{ @@ -469,6 +469,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_image.Rd b/man/fmt_image.Rd index 5448efd28b..7781a9a2f0 100644 --- a/man/fmt_image.Rd +++ b/man/fmt_image.Rd @@ -234,7 +234,7 @@ graphics files on disk. \section{Function ID}{ -3-22 +3-23 } \section{Function Introduced}{ @@ -270,6 +270,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_index.Rd b/man/fmt_index.Rd index df1d1bc9e6..66e0eddc45 100644 --- a/man/fmt_index.Rd +++ b/man/fmt_index.Rd @@ -244,6 +244,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_integer.Rd b/man/fmt_integer.Rd index a52f12834e..97cd6a01ff 100644 --- a/man/fmt_integer.Rd +++ b/man/fmt_integer.Rd @@ -378,6 +378,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_markdown.Rd b/man/fmt_markdown.Rd index fd52ab1feb..06fbe44b51 100644 --- a/man/fmt_markdown.Rd +++ b/man/fmt_markdown.Rd @@ -246,7 +246,7 @@ table (e.g., with \code{\link[=cols_label]{cols_label()}}, \code{\link[=tab_head \section{Function ID}{ -3-26 +3-27 } \section{Function Introduced}{ @@ -285,6 +285,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_number.Rd b/man/fmt_number.Rd index 5a254e81ed..d4fbfbdd00 100644 --- a/man/fmt_number.Rd +++ b/man/fmt_number.Rd @@ -482,6 +482,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_partsper.Rd b/man/fmt_partsper.Rd index 5aee06266b..d8e1312bbc 100644 --- a/man/fmt_partsper.Rd +++ b/man/fmt_partsper.Rd @@ -382,6 +382,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_passthrough.Rd b/man/fmt_passthrough.Rd index ccb37dae6d..1b7ab28625 100644 --- a/man/fmt_passthrough.Rd +++ b/man/fmt_passthrough.Rd @@ -161,7 +161,7 @@ an \code{"s"} character. \section{Function ID}{ -3-27 +3-28 } \section{Function Introduced}{ @@ -197,6 +197,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_percent.Rd b/man/fmt_percent.Rd index 86a665cc9e..8ed9a3bc61 100644 --- a/man/fmt_percent.Rd +++ b/man/fmt_percent.Rd @@ -371,6 +371,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_roman.Rd b/man/fmt_roman.Rd index 628267cd05..6bbcd7024e 100644 --- a/man/fmt_roman.Rd +++ b/man/fmt_roman.Rd @@ -218,6 +218,7 @@ Other data formatting functions: \code{\link{fmt_percent}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_scientific.Rd b/man/fmt_scientific.Rd index 5a8b8abf69..69cf8515ef 100644 --- a/man/fmt_scientific.Rd +++ b/man/fmt_scientific.Rd @@ -383,6 +383,7 @@ Other data formatting functions: \code{\link{fmt_percent}()}, \code{\link{fmt_roman}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_spelled_num.Rd b/man/fmt_spelled_num.Rd index 56aa4e2270..88a8e75439 100644 --- a/man/fmt_spelled_num.Rd +++ b/man/fmt_spelled_num.Rd @@ -330,6 +330,7 @@ Other data formatting functions: \code{\link{fmt_percent}()}, \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/fmt_tf.Rd b/man/fmt_tf.Rd new file mode 100644 index 0000000000..f4584ae402 --- /dev/null +++ b/man/fmt_tf.Rd @@ -0,0 +1,498 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/format_data.R +\name{fmt_tf} +\alias{fmt_tf} +\title{Format \code{TRUE} and \code{FALSE} values} +\usage{ +fmt_tf( + data, + columns = everything(), + rows = everything(), + tf_style = "true-false", + pattern = "{x}", + true_val = NULL, + false_val = NULL, + na_val = NULL, + colors = NULL, + auto_align = TRUE, + locale = NULL +) +} +\arguments{ +\item{data}{\emph{The gt table data object} + +\verb{obj:} // \strong{required} + +This is the \strong{gt} table object that is commonly created through use of the +\code{\link[=gt]{gt()}} function.} + +\item{columns}{\emph{Columns to target} + +\verb{} // \emph{default:} \code{everything()} + +Can either be a series of column names provided in \code{\link[=c]{c()}}, a vector of +column indices, or a select helper function. Examples of select helper +functions include \code{\link[=starts_with]{starts_with()}}, \code{\link[=ends_with]{ends_with()}}, \code{\link[=contains]{contains()}}, +\code{\link[=matches]{matches()}}, \code{\link[=one_of]{one_of()}}, \code{\link[=num_range]{num_range()}}, and \code{\link[=everything]{everything()}}.} + +\item{rows}{\emph{Rows to target} + +\verb{} // \emph{default:} \code{everything()} + +In conjunction with \code{columns}, we can specify which of their rows should +undergo formatting. The default \code{\link[=everything]{everything()}} results in all rows in +\code{columns} being formatted. Alternatively, we can supply a vector of row +captions within \code{\link[=c]{c()}}, a vector of row indices, or a select helper +function. Examples of select helper functions include \code{\link[=starts_with]{starts_with()}}, +\code{\link[=ends_with]{ends_with()}}, \code{\link[=contains]{contains()}}, \code{\link[=matches]{matches()}}, \code{\link[=one_of]{one_of()}}, \code{\link[=num_range]{num_range()}}, and +\code{\link[=everything]{everything()}}. We can also use expressions to filter down to the rows we +need (e.g., \verb{[colname_1] > 100 & [colname_2] < 50}).} + +\item{tf_style}{\emph{Predefined style for \code{TRUE}/\code{FALSE} formatting} + +\verb{scalar|scalar(1<=val<=10)} // \emph{default:} \code{"true-false"} + +The \code{TRUE}/\code{FALSE} mapping style to use. By default this is the short name +\code{"true-false"} which corresponds to the words 'true' and 'false'. Two other +\code{tf_style} values produce words: \code{"yes-no"} and \code{"up-down"}. All three of +these options for \code{tf_style} are locale-aware through the \code{locale} option, +so, a \code{"yes"} value will instead be \code{"ja"} when \code{locale = "de"}. Options +4 through to 10 involve pairs of symbols (e.g., \code{"check-mark"} displays +a check mark for \code{TRUE} and an X symbol for \code{FALSE}).} + +\item{pattern}{\emph{Specification of the formatting pattern} + +\verb{scalar} // \emph{default:} \code{"{x}"} + +A formatting pattern that allows for decoration of the formatted value. The +formatted value is represented by the \code{{x}} (which can be used multiple +times, if needed) and all other characters will be interpreted as string +literals.} + +\item{true_val}{\emph{Text to use for \code{TRUE} values} + +\verb{scalar} // \emph{default:} \code{NULL} (\code{optional}) + +While the choice of a \code{tf_style} will typically supply the \code{true_val} and +\code{false_val} text, we could override this and supply text for any \code{TRUE} +values. This doesn't need to be used in conjunction with \code{false_val}.} + +\item{false_val}{\emph{Text to use for \code{FALSE} values} + +\verb{scalar} // \emph{default:} \code{NULL} (\code{optional}) + +While the choice of a \code{tf_style} will typically supply the \code{true_val} and +\code{false_val} text, we could override this and supply text for any \code{FALSE} +values. This doesn't need to be used in conjunction with \code{true_val}.} + +\item{na_val}{\emph{Text to use for \code{NA} values} + +\verb{scalar} // \emph{default:} \code{NULL} (\code{optional}) + +None of the \code{tf_style} presets will replace any missing values encountered +in the targeted cells. While we always have the option to use +\code{\link[=sub_missing]{sub_missing()}} for \code{NA} replacement, we have the opportunity to do that +here with the \code{na_val} option. This is useful because we also have the +means to add color to the \code{na_val} text or symbol and doing that requires +that a replacement value for \code{NA}s is specified here.} + +\item{colors}{\emph{Colors to use for the resulting strings or symbols} + +\verb{vector} // \emph{default:} \code{NULL} (\code{optional}) + +Providing a vector of color values to \code{colors} will progressively add color +to the formatted result depending on the number of colors provided. With a +single color, all formatted values will be in that color. Giving two colors +results in \code{TRUE} values being the first color, and \code{FALSE} values +receiving the second. With the three color option, the final color will be +given to any \code{NA} values replaced through \code{na_val}.} + +\item{auto_align}{\emph{Automatic alignment of the formatted column} + +\verb{scalar} // \emph{default:} \code{TRUE} + +The input values may have resulted in an alignment that is not as suitable +once formatting has occurred. With \code{auto_align = TRUE}, the formatted +values will be inspected and this may result in a favorable change in +alignment. Typically, symbols will be center aligned whereas words will +receive a left alignment (for words in LTR languages).} + +\item{locale}{\emph{Locale identifier} + +\verb{scalar} // \emph{default:} \code{NULL} (\code{optional}) + +An optional locale identifier that can be used for formatting values +according the locale's rules. Examples include \code{"en"} for English (United +States) and \code{"fr"} for French (France). We can use the \code{\link[=info_locales]{info_locales()}} +function as a useful reference for all of the locales that are supported. A +locale ID can be also set in the initial \code{\link[=gt]{gt()}} function call (where it +would be used automatically by any function with a \code{locale} argument) but a +\code{locale} value provided here will override that global locale.} +} +\value{ +An object of class \code{gt_tbl}. +} +\description{ +There can be times where logical values are useful in a \strong{gt} table. You +might want to express a 'yes' or 'no', a 'true' or 'false', or, perhaps use +pairings of complementary symbols that make sense in a table. The \code{fmt_tf()} +function has a set of \code{tf_style} presets that can be used to quickly map +\code{TRUE}/\code{FALSE} values to strings (which are automatically translated +according to a given \code{locale} value), or, symbols like up/down or left/right +arrows and open/closed shapes. + +While the presets are nice, you can provide your own mappings through the +\code{true_val} and \code{false_val} arguments. With those you could provide text +(perhaps a Unicode symbol?) or even a \strong{fontawesome} icon by using +\code{fontawesome::fa("")}. The function will automatically handle +alignment when \code{auto_align = TRUE} and try to give you the best look +depending on the options chosen. For extra customization, you can also apply +color to the individual \code{TRUE}, \code{FALSE}, and \code{NA} mappings. Just supply +a vector of colors (up to a length of 3) to the \code{colors} argument. +} +\section{Compatibility of formatting function with data values}{ + + +The \code{fmt_tf()} formatting function is compatible with body cells that are +of the \code{"logical"} (preferred) or \code{"numeric"} types. Any other types of body +cells are ignored during formatting. This is to say that cells of +incompatible data types may be targeted, but there will be no attempt to +format them. + +There is a special caveat when attempting to format numerical values: the +values must either be exactly \code{1} (the analogue for \code{TRUE}) or exactly \code{0} +(the analogue for \code{FALSE}). Any other numerical values will be disregarded +and left as is. Because of these restrictions, it is recommended that only +logical values undergo formatting. +} + +\section{Targeting cells with \code{columns} and \code{rows}}{ + + +Targeting of values is done through \code{columns} and additionally by \code{rows} (if +nothing is provided for \code{rows} then entire columns are selected). The +\code{columns} argument allows us to target a subset of cells contained in the +resolved columns. We say resolved because aside from declaring column names +in \code{c()} (with bare column names or names in quotes) we can use +\strong{tidyselect}-style expressions. This can be as basic as supplying a select +helper like \code{starts_with()}, or, providing a more complex incantation like + +\code{where(~ is.numeric(.x) && max(.x, na.rm = TRUE) > 1E6)} + +which targets numeric columns that have a maximum value greater than +1,000,000 (excluding any \code{NA}s from consideration). + +By default all columns and rows are selected (with the \code{everything()} +defaults). Cell values that are incompatible with a given formatting function +will be skipped over, like \code{character} values and numeric \verb{fmt_*()} +functions. So it's safe to select all columns with a particular formatting +function (only those values that can be formatted will be formatted), but, +you may not want that. One strategy is to format the bulk of cell values with +one formatting function and then constrain the columns for later passes with +other types of formatting (the last formatting done to a cell is what you get +in the final output). + +Once the columns are targeted, we may also target the \code{rows} within those +columns. This can be done in a variety of ways. If a stub is present, then we +potentially have row identifiers. Those can be used much like column names in +the \code{columns}-targeting scenario. We can use simpler \strong{tidyselect}-style +expressions (the select helpers should work well here) and we can use quoted +row identifiers in \code{c()}. It's also possible to use row indices (e.g., +\code{c(3, 5, 6)}) though these index values must correspond to the row numbers of +the input data (the indices won't necessarily match those of rearranged rows +if row groups are present). One more type of expression is possible, an +expression that takes column values (can involve any of the available columns +in the table) and returns a logical vector. This is nice if you want to base +formatting on values in the column or another column, or, you'd like to use a +more complex predicate expression. +} + +\section{Compatibility of arguments with the \code{from_column()} helper function}{ + + +The \code{\link[=from_column]{from_column()}} helper function can be used with certain arguments of +\code{fmt_tf()} to obtain varying parameter values from a specified column within +the table. This means that each row could be formatted a little bit +differently. These arguments provide support for \code{\link[=from_column]{from_column()}}: +\itemize{ +\item \code{tf_style} +\item \code{pattern} +\item \code{true_val} +\item \code{false_val} +\item \code{na_val} +\item \code{locale} +} + +Please note that for each of the aforementioned arguments, a \code{\link[=from_column]{from_column()}} +call needs to reference a column that has data of the correct type (this is +different for each argument). Additional columns for parameter values can be +generated with the \code{\link[=cols_add]{cols_add()}} function (if not already present). Columns +that contain parameter data can also be hidden from final display with +\code{\link[=cols_hide]{cols_hide()}}. Finally, there is no limitation to how many arguments the +\code{\link[=from_column]{from_column()}} helper is applied so long as the arguments belong to this +closed set. +} + +\section{Formatting with the \code{tf_style} argument}{ + + +We can supply a preset \code{TRUE}/\code{FALSE} style to the \code{tf_style} argument to +handle the formatting of logical values. There are several such styles and +the first three of them can handle localization to any supported locale +(i.e., the pairs of words for each style will be translated to the language +of the \code{locale}) value. + +The following table provides a listing of all valid \code{tf_style} values and a +description of their output values. The output from styles \code{4} to \code{10} are +described in terms of the Unicode character names used for the \code{TRUE} and +\code{FALSE} values.\tabular{lll}{ + \tab TF Style \tab Output (for \code{TRUE} and \code{FALSE}) \cr + 1 \tab \code{"true-false"} \tab \code{"true"}, \code{"false"} (\code{locale}-aware) \cr + 2 \tab \code{"yes-no"} \tab \code{"yes"}, \code{"no"} (\code{locale}-aware) \cr + 3 \tab \code{"up-down"} \tab \code{"up"}, \code{"down"} (\code{locale}-aware) \cr + 4 \tab \code{"check-mark"} \tab \verb{}, \verb{} \cr + 5 \tab \code{"circles"} \tab \verb{}, \verb{} \cr + 6 \tab \code{"squares"} \tab \verb{}, \verb{} \cr + 7 \tab \code{"diamonds"} \tab \verb{}, \verb{} \cr + 8 \tab \code{"arrows"} \tab \verb{}, \verb{} \cr + 9 \tab \code{"triangles"} \tab \verb{}, \verb{} \cr + 10 \tab \code{"triangles-lr"} \tab \verb{}, \verb{} \cr +} +} + +\section{Adapting output to a specific \code{locale}}{ + + +This formatting function can adapt outputs according to a provided \code{locale} +value. Examples include \code{"en"} for English (United States) and \code{"fr"} for +French (France). Note that a \code{locale} value provided here will override any +global locale setting performed in \code{\link[=gt]{gt()}}'s own \code{locale} argument (it is +settable there as a value received by all other functions that have a +\code{locale} argument). As a useful reference on which locales are supported, we +can use the \code{\link[=info_locales]{info_locales()}} function to view an info table. +} + +\section{Examples}{ + + +Let's use a subset of the \code{\link{sp500}} dataset to create a small \strong{gt} table +containing opening and closing price data for a week in 2013. We can add +a logical column (\code{dir}) with the \code{\link[=cols_add]{cols_add()}} function; the expression used +determines whether the \code{close} value is greater than the \code{open} value. That +new column is inserted between \code{open} and \code{close}. Then, we use the +\code{fmt_tf()} function to generate up and down arrows in the \code{dir} column. We +elect to use green upward arrows and red downward arrows (through the +\code{colors} option). With a little numeric formatting and changes to the column +labels, the table becomes more presentable. + +\if{html}{\out{
}}\preformatted{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 = "" + ) +}\if{html}{\out{
}} + +\if{html}{\out{ +This image of a table was generated from the first code example in the `fmt_tf()` help file. +}} + +The \code{\link{reactions}} dataset contains chemical kinetic information on a wide +variety of atmospherically-relevant compounds. It might be interesting to get +a summary (for a small subset of compounds) for which rate constants are +available for the selected compounds. We first start by selecting the +relevant rows and columns. Then we generate logical columns for each of the +reaction types (i.e., if a value is \code{NA} then there's no measurement, so +that's \code{FALSE}). Once the \strong{gt} table has been created, we can use +\code{fmt_tf()} to provide open and filled circles to indicate whether a +particular reaction has been measured and presented in the literature. + +\if{html}{\out{
}}\preformatted{reactions |> + dplyr::filter(cmpd_type \%in\% c("carboxylic acid", "alkyne", "allene")) |> + dplyr::select(cmpd_name, cmpd_type, ends_with("k298")) |> + dplyr::mutate(across(ends_with("k298"), is.na)) |> + gt(rowname_col = "cmpd_name", groupname_col = "cmpd_type") |> + tab_spanner( + label = "Has a measured rate constant", + columns = ends_with("k298") + ) |> + tab_stub_indent( + rows = everything(), + indent = 2 + ) |> + fmt_tf( + columns = ends_with("k298"), + tf_style = "circles" + ) |> + cols_label( + OH_k298 = "OH", + O3_k298 = "Ozone", + NO3_k298 = "Nitrate", + Cl_k298 = "Chlorine" + ) |> + cols_width( + stub() ~ px(200), + ends_with("k298") ~ px(80) + ) |> + opt_vertical_padding(scale = 0.35) +}\if{html}{\out{
}} + +\if{html}{\out{ +This image of a table was generated from the second code example in the `fmt_tf()` help file. +}} + +There are census-based population values in the \code{\link{towny}} dataset and quite a +few small towns within it. Let's look at the ten smallest towns (according +to the 2021 figures) and work out whether their populations have increased or +declined since 1996. Also, let's determine which of these towns even have a +website. After that data preparation, the data is made into a \strong{gt} table +and \code{fmt_tf()} can be used in the \code{website} and \code{pop_dir} columns (which both +have \code{TRUE}/\code{FALSE} values). Each of these \code{fmt_tf()} calls will either +produce \code{"yes"}/\code{"no"} or \code{"up"}/\code{"down"} strings (set via the \code{tf_style} +option). + +\if{html}{\out{
}}\preformatted{towny |> + dplyr::arrange(population_2021) |> + dplyr::mutate(website = !is.na(website)) |> + dplyr::mutate(pop_dir = population_2021 > population_1996) |> + dplyr::select(name, website, population_1996, population_2021, pop_dir) |> + dplyr::slice_head(n = 10) |> + gt(rowname_col = "name") |> + tab_spanner( + label = "Population", + columns = starts_with("pop") + ) |> + tab_stubhead(label = "Town") |> + fmt_tf( + columns = website, + tf_style = "yes-no", + auto_align = FALSE + ) |> + fmt_tf( + columns = pop_dir, + tf_style = "up-down", + pattern = "It's \{x\}." + ) |> + cols_label_with( + columns = starts_with("population"), + fn = function(x) sub("population_", "", x) + ) |> + cols_label( + website = md("Has a \\n website?"), + pop_dir = "Pop. direction?" + ) |> + opt_horizontal_padding(scale = 2) +}\if{html}{\out{
}} + +\if{html}{\out{ +This image of a table was generated from the third code example in the `fmt_tf()` help file. +}} + +If formatting to words instead of symbols (with the hyphenated \code{tf_style} +keywords), the words themselves can be translated to different languages +if providing a \code{locale} value. In this next example, we're manually creating +a tibble with locale codes and their associated languages. The \code{yes} and \code{up} +columns all receive \code{TRUE} whereas \code{no} and \code{down} will all be \code{FALSE}. +With two calls of \code{fmt_tf()} for each of these pairings, we get the columns' +namesake words. To have these words translated, the \code{locale} argument is +pointed toward values in the \code{code} column by using the \code{\link[=from_column]{from_column()}} +helper function. + +\if{html}{\out{
}}\preformatted{dplyr::tibble( + code = c("de", "fr", "is", "tr", "ka", "lt", "ca", "bg", "lv"), + lang = c( + "German", "French", "Icelandic", "Turkish", "Georgian", + "Lithuanian", "Catalan", "Bulgarian", "Latvian" + ), + yes = TRUE, + no = FALSE, + up = TRUE, + down = FALSE +) |> + gt(rowname_col = "lang") |> + tab_header(title = "Common words in a few languages") |> + fmt_tf( + columns = c(yes, no), + tf_style = "yes-no", + locale = from_column("code") + ) |> + fmt_tf( + columns = c(up, down), + tf_style = "up-down", + locale = from_column("code") + ) |> + cols_merge( + columns = c(lang, code), + pattern = "\{1\} (\{2\})" + ) |> + cols_width( + stub() ~ px(150), + everything() ~ px(80) + ) +}\if{html}{\out{
}} + +\if{html}{\out{ +This image of a table was generated from the fourth code example in the `fmt_tf()` help file. +}} +} + +\section{Function ID}{ + +3-18 +} + +\section{Function Introduced}{ + +\emph{In Development} +} + +\seealso{ +Other data formatting functions: +\code{\link{data_color}()}, +\code{\link{fmt}()}, +\code{\link{fmt_auto}()}, +\code{\link{fmt_bins}()}, +\code{\link{fmt_bytes}()}, +\code{\link{fmt_chem}()}, +\code{\link{fmt_country}()}, +\code{\link{fmt_currency}()}, +\code{\link{fmt_date}()}, +\code{\link{fmt_datetime}()}, +\code{\link{fmt_duration}()}, +\code{\link{fmt_email}()}, +\code{\link{fmt_engineering}()}, +\code{\link{fmt_flag}()}, +\code{\link{fmt_fraction}()}, +\code{\link{fmt_icon}()}, +\code{\link{fmt_image}()}, +\code{\link{fmt_index}()}, +\code{\link{fmt_integer}()}, +\code{\link{fmt_markdown}()}, +\code{\link{fmt_number}()}, +\code{\link{fmt_partsper}()}, +\code{\link{fmt_passthrough}()}, +\code{\link{fmt_percent}()}, +\code{\link{fmt_roman}()}, +\code{\link{fmt_scientific}()}, +\code{\link{fmt_spelled_num}()}, +\code{\link{fmt_time}()}, +\code{\link{fmt_units}()}, +\code{\link{fmt_url}()}, +\code{\link{sub_large_vals}()}, +\code{\link{sub_missing}()}, +\code{\link{sub_small_vals}()}, +\code{\link{sub_values}()}, +\code{\link{sub_zero}()} +} +\concept{data formatting functions} diff --git a/man/fmt_time.Rd b/man/fmt_time.Rd index 8cc1097dd5..4ab28a993e 100644 --- a/man/fmt_time.Rd +++ b/man/fmt_time.Rd @@ -322,6 +322,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, \code{\link{sub_large_vals}()}, diff --git a/man/fmt_units.Rd b/man/fmt_units.Rd index bb7bc865c2..e0a58896f4 100644 --- a/man/fmt_units.Rd +++ b/man/fmt_units.Rd @@ -198,7 +198,7 @@ but rather \code{" ^-1"}). \section{Function ID}{ -3-18 +3-19 } \section{Function Introduced}{ @@ -235,6 +235,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_url}()}, \code{\link{sub_large_vals}()}, diff --git a/man/fmt_url.Rd b/man/fmt_url.Rd index 7769d3e7c9..f6ff1c6359 100644 --- a/man/fmt_url.Rd +++ b/man/fmt_url.Rd @@ -337,7 +337,7 @@ you to handle them with \code{\link[=sub_missing]{sub_missing()}}. Here's an exa \section{Function ID}{ -3-20 +3-21 } \section{Function Introduced}{ @@ -374,6 +374,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{sub_large_vals}()}, diff --git a/man/sub_large_vals.Rd b/man/sub_large_vals.Rd index f0d020ef5f..18a1cd2d60 100644 --- a/man/sub_large_vals.Rd +++ b/man/sub_large_vals.Rd @@ -189,7 +189,7 @@ omitted. \section{Function ID}{ -3-33 +3-34 } \section{Function Introduced}{ @@ -226,6 +226,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/sub_missing.Rd b/man/sub_missing.Rd index 3369701794..4f412302df 100644 --- a/man/sub_missing.Rd +++ b/man/sub_missing.Rd @@ -126,7 +126,7 @@ calls of \code{sub_missing()}. \section{Function ID}{ -3-30 +3-31 } \section{Function Introduced}{ @@ -163,6 +163,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/sub_small_vals.Rd b/man/sub_small_vals.Rd index 187c5a12e1..5e9a3cecc1 100644 --- a/man/sub_small_vals.Rd +++ b/man/sub_small_vals.Rd @@ -192,7 +192,7 @@ omitted. \section{Function ID}{ -3-32 +3-33 } \section{Function Introduced}{ @@ -229,6 +229,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/sub_values.Rd b/man/sub_values.Rd index 3362e52c16..87a147b4ef 100644 --- a/man/sub_values.Rd +++ b/man/sub_values.Rd @@ -209,7 +209,7 @@ that vector must match the length of \code{x}). \section{Function ID}{ -3-34 +3-35 } \section{Function Introduced}{ @@ -246,6 +246,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/man/sub_zero.Rd b/man/sub_zero.Rd index 6b52c44290..3197ccf0b8 100644 --- a/man/sub_zero.Rd +++ b/man/sub_zero.Rd @@ -131,7 +131,7 @@ single call of \code{sub_zero()}. \section{Function ID}{ -3-31 +3-32 } \section{Function Introduced}{ @@ -168,6 +168,7 @@ Other data formatting functions: \code{\link{fmt_roman}()}, \code{\link{fmt_scientific}()}, \code{\link{fmt_spelled_num}()}, +\code{\link{fmt_tf}()}, \code{\link{fmt_time}()}, \code{\link{fmt_units}()}, \code{\link{fmt_url}()}, diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 38e46dfd8f..71fd26eaad 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -94,6 +94,7 @@ reference: - fmt_datetime - fmt_duration - fmt_bins + - fmt_tf - fmt_markdown - fmt_units - fmt_chem