The fmt_auto() function

Use the exibble dataset to create a gt table. Format all of the columns automatically with the fmt_auto() function.

exibble |>
  gt() |>
  fmt_auto()
num char fctr date time datetime currency row group
0.111 apricot one 2015-01-15 13:35 2018-01-01 02:22     49.95  row_1 grp_a
2.222 banana two 2015-02-15 14:40 2018-02-02 14:33     17.95  row_2 grp_a
33.33 coconut three 2015-03-15 15:45 2018-03-03 03:44      1.39  row_3 grp_a
444.4 durian four 2015-04-15 16:50 2018-04-04 15:55 65,100     row_4 grp_a
5,550 NA five 2015-05-15 17:55 2018-05-05 04:00  1,325.81  row_5 grp_b
NA fig six 2015-06-15 NA 2018-06-06 16:11     13.255 row_6 grp_b
777,000 grapefruit seven NA 19:10 2018-07-07 05:22 NA row_7 grp_b
8.880 × 106 honeydew eight 2015-08-15 20:20 NA      0.44  row_8 grp_b

Let’s now use the countrypops dataset to create another gt table. We’ll again use fmt_auto() to automatically format all columns but this time the choice will be made to opt for large-number suffixing instead of scientific notation. This is done by using the lg_num_pref = "suf" option.

countrypops |>
  dplyr::select(country_code_3, year, population) |>
  dplyr::filter(country_code_3 %in% c("CHN", "IND", "USA", "PAK", "IDN")) |>
  dplyr::filter(year > 1975 & year %% 5 == 0) |>
  tidyr::spread(year, population) |>
  dplyr::arrange(desc(`2020`)) |>
  gt(rowname_col = "country_code_3") |>
  fmt_auto(lg_num_pref = "suf")
1980 1985 1990 1995 2000 2005 2010 2015 2020
CHN 981.2M 1.1B 1.1B 1.2B 1.3B 1.3B 1.3B 1.4B 1.4B
IND 696.8M 780.2M 870.5M 964.3M 1.1B 1.2B 1.2B 1.3B 1.4B
USA 227.2M 237.9M 249.6M 266.3M 282.2M 295.5M 309.3M 320.7M 331.5M
IDN 148.2M 165.8M 182.2M 198.1M 214.1M 228.8M 244M 259.1M 271.9M
PAK 80.6M 97.1M 115.4M 133.1M 154.4M 174.4M 194.5M 211M 227.2M