Consider the example data.frame
df <- data.frame( id = 1:4, name = c("Bob", "Ashley", "James", "David"), age = c(48, NA, 40, 28), test1_score = c(18.9, 19.5, NA, 12.9), stringsAsFactors = FALSE)
I use R package, able to make a beautiful table.
library(formattable) formattable(df, list( age = color_tile("white", "orange"), test1_score = color_bar("pink", 'proportion', 0.2) ))

It used to be that NA was not automatically printed, and instead a space was printed. It doesn't seem to be the default anymore, but I would still like to print a space for NA. Replacing NA, how it works:
df[is.na(df)]='' formattable(df, list( age = color_tile("white", "orange"), test1_score = color_bar("pink", 'proportion', 0.2) ))

However, if I try to format one of the columns to make it have 2 decimal places, then the annoying NA return:
df$age = digits(df$age, digits=2) formattable(df, list( age = color_tile("white", "orange"), test1_score = color_bar("pink", 'proportion', 0.2) ))

If I delete NA again, NA will disappear, but so will the decimal places
df[is.na(df)] = '' formattable(df, list( age = color_tile("white", "orange"), test1_score = color_bar("pink", 'proportion', 0.2) ))

I believe the reason is that numbers convert df$age to a formattable numeric object and create NA , and df[is.na(df)] = '' converts df$age to a formattable character object:
> df$age = digits(df$age, digits=2) > df$age [1] 48.00 NA 40.00 28.00 > class(df$age) [1] "formattable" "numeric" > df[is.na(df)] = '' > df$age [1] "48" " " "40" "28" > class(df$age) [1] "formattable" "character"
Any ideas for a solution?
Ultimately, I would also like to use this with filtered data.frame, where I use the code from Formatted Filtering Data Frames to ensure that the color bar remains the same when filtering .frame data:
df$age = digits(df$age, digits=2) subset_df <- function(m) { formattable(df[m, ], list( age = x ~ color_tile("white", "orange")(df$age)[m], test1_score = x ~ color_bar("pink", 'proportion', 0.2)(df$test1_score)[m], test2_score = x ~ color_bar("pink", 'proportion', 0.2)(df$test2_score)[m] )) } subset_df(1:3)

The problem does not seem to be related to this code.