Learn R Programming

ratlas (version 0.1.1)

fmt_table: Center and Decimal Align Tables

Description

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

Usage

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

Value

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

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).

See Also

Other formatters: formatting, padding

Examples

Run this code
pcts <- tibble::tibble(n = 0:5, p = 0.5 * (0:5))
pcts %>% fmt_table()

Run the code above in your browser using DataLab