formattable.numeric: Create a formattable numeric vector

Description Usage Arguments Value Examples

View source: R/formattable.R

Description

Create a formattable numeric vector

Usage

1
2
## S3 method for class 'numeric'
formattable(x, ..., formatter = "formatC", preproc = NULL, postproc = NULL)

Arguments

x

a numeric vector.

...

arguments to be passed to formatter.

formatter

formatting function, formatC in default.

preproc

pre-processor function that prepares x for formatting function.

postproc

post-processor function that transforms formatted output for printing.

Value

a formattable numeric vector.

Examples

1
2
3
4
5
6
7
8
formattable(rnorm(10), format = "f", digits = 1)
formattable(rnorm(10), format = "f",
  flag="+", digits = 1)
formattable(1:10,
  postproc = function(str, x) paste0(str, "px"))
formattable(1:10,
  postproc = function(str, x)
    paste(str, ifelse(x <= 1, "unit", "units")))

Example output

 [1] 0.0  -1.1 -0.1 -1.0 1.7  1.1  0.2  2.4  1.2  1.8 
 [1] +1.3 +0.3 +0.3 -1.7 +0.1 -0.4 +1.0 -1.0 -0.5 +2.6
 [1] 1px  2px  3px  4px  5px  6px  7px  8px  9px  10px
 [1] 1 unit   2 units  3 units  4 units  5 units  6 units  7 units  8 units 
 [9] 9 units  10 units

formattable documentation built on Jan. 13, 2021, 7:17 a.m.