I am fairly new to formattable and am trying to output a R Markdown document with different sales figures. I am preparing the figures and then display them using formattable.
I use the following code to create and format the table. The q_line input is a data.frame containing employee names in the first column and numbers in the following columns, example data as follows:
| Column A | Column B |
|---|---|
| Jane | -10000 |
| John | +5000 |
formattable(q_line,
align = c("l", rep("r", ncol(q_line)-1)), list(
area(, col = 2:ncol(q_line)) ~ num_format,
area(row = nrow(q_line)) ~ last_row
)
)
I also define the num_format format as follows:
num_format <- function(x) {
x <- currency(x, symbol = "CHF", sep = " ", digits = 0L, format = "d", big.mark= "'")
}
When I enter a negative number (e.g. -10000) to num_format, the result is as expected (i.e. returning "CHF -10'000"). However, in the formattable output, the number shows as a positive, i.e. "CHF 10'000".
I tried to find where the "-" is dropped by not applying the num_format to the formattable (worked), by using the num_format function outside formattable (worked) and using accounting instead of currency function for formattable (worked, but the result is not satisfactory).
Any ideas why the "-" is not displayed?