Automatic formatting for tables that should "just work" for most use cases. For more fine-grained control, see formatting and padding.

fmt_table(
  df,
  dec_dig = 1,
  prop_dig = 3,
  corr_dig = 3,
  output = NULL,
  fmt_small = TRUE,
  max_value = NULL,
  keep_zero = FALSE
)

Arguments

df

A data frame or tibble to be formatted for printing in output.

dec_dig

The number of decimal places to include for numbers, e.g., dec_dig = 1 for 16.5.

prop_dig

The number of decimal places to include for numbers bounded between [0,1], e.g., prop_dig = 2 for .35.

corr_dig

The number of decimal places to include for numbers bounded between [-1,1], e.g., corr_dig = 3 for .205.

output

The output format of the table. One of "latex" or "html". Automatically pulled from document output type if not specified.

fmt_small

Indicator for replacing zero with < (e.g., .000 becomes <.001). Default is TRUE.

max_value

If fmt_small is TRUE and a max_value is supplied, any value greater than the max_value is replaced with > (e.g., if max_value = 50, then 60 becomes >49.9). The number of digits depends on either dec_digits, prop_dig, or corr_dig.

keep_zero

If fmt_small is TRUE, whether to preserve true 0s (e.g., 0.0000001 becomes <.001, but 0.0000000 stays .000).

Value

A tibble with the same rows and columns as df, with numbers formatted consistently and padded for alignment when printed.

See also

Other formatters: formatting, padding

Examples

pcts <- tibble::tibble(n = 0:5, p = 0.5 * (0:5))
pcts |> fmt_table()
#> # A tibble: 6 × 2
#>   n     p           
#>   <chr> <chr>       
#> 1 0     "<0.1\\ \\ "
#> 2 1     "0.5"       
#> 3 2     "1.0"       
#> 4 3     "1.5"       
#> 5 4     "2.0"       
#> 6 5     "2.5"