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 -1.6 0.2  -1.1 -0.1 -0.7 1.4  -0.8 -1.5 1.1 
formattable(rnorm(10), format = "f",
  flag="+", digits = 1)
#>  [1] -1.3 -1.8 -0.1 +0.7 -1.1 +0.3 +0.5 +0.8 +1.3 -0.8
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