number_format

0th

Percentile

Number format

Functions to get or set the number format property of huxtable table cells.

Usage
number_format(ht)
number_format(ht) <- value
set_number_format(ht, row, col, value, byrow = FALSE)
Arguments
ht

A huxtable.

value

A vector or list which may be character, numeric or function. See below. 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.

Details

If value is numeric, numbers will be rounded to that many decimal places. If value is character, it will be taken as an argument to sprintf. If value is a function it will be applied to the cell contents. Number format is applied to any cells that look like numbers (as judged by as.numeric), not just to numeric cells. This allows you to do e.g. ht <- huxtable(c('Salary', 35000, 32000, 40000)) and still format numbers correctly. To set number_format to a function, enclose the function in list. See the examples.

Value

For number_format, the number_format attribute. For set_number_format, the ht object.

See Also

Other formatting functions: background_color, bold, font_size, font, na_string, text_color

Aliases
  • number_format
  • number_format<-
  • set_number_format
  • number_format.huxtable
  • number_format<-.huxtable
Examples
# NOT RUN {
ht <- huxtable(a = 10^(3:6) + (5 * 10^(-2:-5)), b = 10^(3:6) + (5* 10^(-2:-5)))
number_format(ht)[1,] <- 2
number_format(ht)[2,] <- '%5.2f'
number_format(ht)[3,] <- list(function(x) prettyNum(x, big.mark = ','))
number_format(ht)[4,] <- list(function(x) if(x>0) '+' else '-')
ht
print_screen(ht)

ht <- huxtable(a = 1:3, b = 3:1)
ht2 <- set_number_format(ht, 2)
number_format(ht2)
ht3 <- set_number_format(ht, 1:2, 1, 2)
number_format(ht3)
ht4 <- set_number_format(ht, 1:2, 1:2, c(2, 3), byrow = TRUE)
number_format(ht4)
ht5 <- set_number_format(ht, where(ht == 1), 2)
number_format(ht5)
# }
Documentation reproduced from package huxtable, version 1.2.0, License: MIT + file LICENSE

Community examples

Looks like there are no examples yet.