huxtable (version 0.2.0)

pad_decimal: Decimal padding

Description

Functions to get or set the decimal padding property of huxtable table cells.

Usage

pad_decimal(ht)
pad_decimal(ht) <- value
set_pad_decimal(ht, row, col, value, byrow = FALSE)

Arguments

ht
A huxtable.
value
A vector of single characters. NA is the default of no padding. Set to NA to reset to the default.
row
A row specifier. See rowspecs for details.
col
An optional column specifier.
byrow
If TRUE, fill in values by row rather than by column.

Value

For pad_decimal, the pad_decimal attribute. For set_pad_decimal, the ht object.

Details

LaTeX and HTML both have no simple way to align columns on decimal points, especially when cells may contain non-mathematical content like significance stars. To right-pad cells in a column to align on the rightmost decimal point, set pad_decimal to '.' or whatever decimal you prefer to use.

Examples

Run this code
vals <- c(1.00035, 22, "2.34 *", "(11.5 - 22.3)", "Do not pad this row.")
ht <- hux(NotPadded = vals, Padded = vals)
number_format(ht)       <- '%2.6g'
align(ht)[1:5,]         <- 'right'
pad_decimal(ht)[1:4, 2] <- '.'
ht

ht <- huxtable(a = 1:3, b = 3:1)
ht2 <- set_pad_decimal(ht, '.')
pad_decimal(ht2)
ht3 <- set_pad_decimal(ht, 1:2, 1, '.')
pad_decimal(ht3)
ht4 <- set_pad_decimal(ht, 1:2, 1:2, c('.', NA), byrow = TRUE)
pad_decimal(ht4)
ht5 <- set_pad_decimal(ht, where(ht == 1), '.')
pad_decimal(ht5)

Run the code above in your browser using DataCamp Workspace