Skip to content

Commit 5de03a5

Browse files
authored
Merge pull request #1646 from rstudio/add-documentation-example
Add documentation example
2 parents 731b8b1 + 5f6ff36 commit 5de03a5

File tree

4 files changed

+93
-6
lines changed

4 files changed

+93
-6
lines changed

R/format_data.R

+47-3
Original file line numberDiff line numberDiff line change
@@ -4880,6 +4880,50 @@ get_letters_from_div <- function(x, set) {
48804880
#' `r man_get_image_tag(file = "man_fmt_spelled_num_2.png")`
48814881
#' }}
48824882
#'
4883+
#' Let's make a table that compares how the numbers from `1` to `10` are spelled
4884+
#' across a small selection of languages. Here we use `fmt_spelled_num()` with
4885+
#' each column, ensuring that the `locale` value matches that of the column
4886+
#' name.
4887+
#'
4888+
#' ```r
4889+
#' dplyr::tibble(
4890+
#' num = 1:10,
4891+
#' en = num,
4892+
#' fr = num,
4893+
#' de = num,
4894+
#' es = num,
4895+
#' pl = num,
4896+
#' bg = num,
4897+
#' ko = num,
4898+
#' zh = num
4899+
#' ) |>
4900+
#' gt(rowname_col = "num") |>
4901+
#' fmt_spelled_num(columns = en, locale = "en") |>
4902+
#' fmt_spelled_num(columns = fr, locale = "fr") |>
4903+
#' fmt_spelled_num(columns = de, locale = "de") |>
4904+
#' fmt_spelled_num(columns = es, locale = "es") |>
4905+
#' fmt_spelled_num(columns = pl, locale = "pl") |>
4906+
#' fmt_spelled_num(columns = bg, locale = "bg") |>
4907+
#' fmt_spelled_num(columns = ko, locale = "ko") |>
4908+
#' fmt_spelled_num(columns = zh, locale = "zh") |>
4909+
#' cols_label_with(fn = function(x) md(paste0("`", x, "`"))) |>
4910+
#' tab_spanner(
4911+
#' label = "Numbers in the specified locale",
4912+
#' columns = everything()
4913+
#' ) |>
4914+
#' cols_align(align = "left", columns = everything()) |>
4915+
#' cols_width(
4916+
#' c(en, fr, de, es, pl, bg) ~ px(100),
4917+
#' c(ko, zh) ~ px(50)
4918+
#' ) |>
4919+
#' opt_horizontal_padding(scale = 2) |>
4920+
#' opt_vertical_padding(scale = 0.5)
4921+
#' ```
4922+
#'
4923+
#' \if{html}{\out{
4924+
#' `r man_get_image_tag(file = "man_fmt_spelled_num_3.png")`
4925+
#' }}
4926+
#'
48834927
#' @family data formatting functions
48844928
#' @section Function ID:
48854929
#' 3-11
@@ -8655,13 +8699,13 @@ fmt_units <- function(
86558699
#' automatically stylized to fit conventions; `"NO_x"` and `"x Na(NH4)HPO4"`
86568700
#' will have italicized 'x' characters and you can always italicize letters
86578701
#' by surrounding with `"*"` (as in `"*n* H2O"` or `"*n*-C5H12"`)
8658-
#' - Chemical isotopes can be rendered using either of these two construction
8702+
#' - Chemical isotopes can be rendered using either of these two constructions
86598703
#' preceding an element: `"^{227}_{90}Th"` or `"^227_90Th"`; nuclides can
86608704
#' be represented in a similar manner, here are two examples:
86618705
#' `"^{0}_{-1}n^{-}"`, `"^0_-1n-"`
86628706
#' - Chemical reactions can use `"+"` signs and a variety of reaction arrows:
8663-
#' (1) "A -> B", (2) "A <- B", (3) "A <-> B", (4) "A <--> B", (5) "A <=> B",
8664-
#' (6) "A <=>> B", or (7) "A <<=> B"
8707+
#' (1) `"A -> B"`, (2) `"A <- B"`, (3) `"A <-> B"`, (4) `"A <--> B"`, (5)
8708+
#' `"A <=> B"`, (6) `"A <=>> B"`, or (7) `"A <<=> B"`
86658709
#' - Center dots (useful in addition compounds) can be added by using a single
86668710
#' `"."` or `"*"` character, surrounded by spaces; here are two equivalent
86678711
#' examples `"KCr(SO4)2 . 12 H2O"` and `"KCr(SO4)2 * 12 H2O"`

images/man_fmt_spelled_num_3.png

156 KB
Loading

man/fmt_chem.Rd

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fmt_spelled_num.Rd

+43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)