padding: Table Padding

paddingR Documentation

Table Padding

Description

A family of functions for formatting numbers and then padding with spaces so that table columns can be both centered and decimal aligned.

Usage

pad_counts(x, digits = 0L)

pad_prop(x, digits, fmt_small = TRUE, keep_zero = FALSE, output = NULL)

pad_corr(x, digits, output = NULL)

pad_decimal(
  x,
  digits,
  fmt_small = FALSE,
  max_value = NULL,
  keep_zero = FALSE,
  output = NULL
)

Arguments

x

Number or number string to be formatted

digits

Number of decimal places to retain

fmt_small

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

keep_zero

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

output

The output type for the rendered document. One of "latex" or "html".

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

Details

pad_counts should be used to pad integer numbers. This wraps base::format() to add a comma separator.

pad_prop should be used to pad decimal numbers between [0,1]. This wraps fmt_prop() to round to a specified number of digits and optionally remove the leading zero.

pad_corr should be used to pad decimal numbers between [-1,1]. This wraps fmt_corr(), and is similar to pad_prop, but accounts for negative numbers when adding padding.

pad_decimal should be used to pad decimal number that are not bounded. This wraps fmt_digits() to round to a specified number of decimal places.

Value

A character vector of the same length as x.

See Also

Other formatters: fmt_table(), formatting

Examples

pad_counts(sample(1:1000, size = 20))

pad_prop(c(0.001, runif(5)), digits = 2)

pad_corr(runif(10, -1, 1), digits = 2)

pad_decimal(runif(10, 1, 100), digits = 1)

ratlas documentation built on April 4, 2025, 12:22 a.m.