Create a formattable numeric vector

# 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

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