I've found the package condformat, that easily creates coloured tables from data.frames.
You can run one of its examples.
data(iris)
library(condformat)
condformat(iris[c(1:5,70:75, 120:125),]) +
rule_fill_discrete(Species) +
rule_fill_discrete(Sepal.Width, Sepal.Length,expression = Sepal.Width > Sepal.Length - 2.25, colours = c("TRUE" = "#7D00FF")) + rule_fill_gradient2(Petal.Length)
I can use it within a markdown document if I generate an html.
But I'm not able to use it to generate a pdf. I've tried both with knitr and with rmarkdown. Knitr produces the error:
Overfull \hbox (22.4968pt too wide) in paragraph at lines 62--62
Missing $ inserted.
and many
You can't use `macro parameter character #' in math mode.
And when I try to embed the code within a rmarkdown chunk it doesn't produce any error but the output it's just a single column with many numbers, without colours.
I've tried both with results='asis' and without it.
How can I get these tables when creating a pdf with a Rnw Knitr?
Sometimes I get similar results with xtable or or ztable but the former is very difficult if you want to selectively colour cells, and the latter doesn't work well sometimes. For example I'm not able to print numbers in scientific format inside a ztable table.