pretty_number {TableContainer}R Documentation

Common functions for formatting table cells

Description

Common functions for formatting table cells

Common functions for formatting table cells

Usage

pretty_number(x, max_len = 20)

common_formatter(x, max_len = 20)

Arguments

x

A vector of values to format.

max_len

The maximum length for the formatted string.

Details

pretty_number : keep all digits if we can keep it within the width limit. Otherwise, use scientific notation to reduce length. If the number still cannot fit within the length limit, return the shortest result.

common_formatter : For numeric, call pretty_number to format the number. For non-numeric, truncate the string and append "..." if it exceeds the width limit.

Value

A character string with the formatted number. If the number cannot fit within the specified maximum length, scientific notation is used with reduced digits.

A character vector of the same length as x with formatted values. For numeric values, uses pretty_number() formatting. For non-numeric values, truncates strings longer than max_len and appends "..." if needed.

See Also

format_tbl() for formatting tables

Examples

## Format a number
pretty_number(1234567890, max_len = 20)
pretty_number(1234567890, max_len = 8)
pretty_number(1234567890, max_len = 3)
## format character
common_formatter("this is a long string", max_len = 40)
common_formatter("this is a long string", max_len = 20)

[Package TableContainer version 1.0.0 Index]