Create a formattable numeric vector

# S3 method for 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

formattable(rnorm(10), format = "f", digits = 1)
#>  [1] 0.4  0.9  0.4  0.6  -0.0 -1.1 -0.4 -0.9 -1.0 -0.9
formattable(rnorm(10), format = "f",
  flag="+", digits = 1)
#>  [1] +0.4 -1.0 -0.4 -0.7 -1.7 -0.0 +2.0 +1.1 +0.3 +0.4
formattable(1:10,
  postproc = function(str, x) paste0(str, "px"))
#>  [1] 1px  2px  3px  4px  5px  6px  7px  8px  9px  10px
formattable(1:10,
  postproc = function(str, x)
    paste(str, ifelse(x <= 1, "unit", "units")))
#>  [1] 1 unit   2 units  3 units  4 units  5 units  6 units  7 units  8 units 
#>  [9] 9 units  10 units