R/helpers-cross_tab.R

Defines functions strip_ansi format_number_x2 center_text_x2

center_text_x2 = function(text, width) {
    text_width = nchar(strip_ansi(text))
    padding = max(0, width - text_width)
    left_padding = floor(padding / 2)
    right_padding = ceiling(padding / 2)
    paste0(strrep(" ", left_padding), text, strrep(" ", right_padding))
}

format_number_x2 = function(x) {
    vctrs::vec_if_else(
        abs(x - round(x)) < 1e-10,
        sprintf("%d", round(x)),
        sprintf("%.1f", x)
    )
}

strip_ansi = function(text) {
    gsub("\033\\[[0-9;]*m", "", text)
}

Try the tabstats package in your browser

Any scripts or data that you put into this service are public.

tabstats documentation built on July 8, 2026, 5:07 p.m.