I would like to used custom classes to display large number nicely with pandoc.tables (I am using pander), while knitting html or pdf.
I found a way to print nicely in the console thanks to this SO question.
In this example, printing x returns 6M 75M 743.5M 0.3M 4.3M:
print.million <- function(x, ...) {
x <- paste0(round(x / 1e6, 1), "M")
NextMethod(x, quote = FALSE, ...)
}
x <- c(6e+06, 75000400, 743450000, 340000, 4300000)
class(x) <- "million"
x
but this formatting disappears with pandoc.table: the original, unformatted values are displayed. I have tried custom formatting as well (answer of the SO question above):
format.million <- function(x,...)paste0(round(unclass(x) / 1e6, 1), "M")
as.data.frame.million <- base:::as.data.frame.factor
But without success.
Is there a way to make this work ? I am open to solutions other than pander, but kable does not seem compatible with my version of R (R version 3.2.3).