I am still working on this question. I've got it so it gives the correct cells red backgrounds, but it is not giving the other cells green backgrounds.
Note: I am using sweave only, not knitr.
Here is my code:
<<>>=
Flag <- data.frame(HOSP,Dept, Overall, DC_Info, Care_Trans)
@
<<results=tex>>=
color_cells <- function(df, var){
out <- ifelse(df[, var]=="",
paste0("\\cellcolor[HTML]{2DB200}{", df[, var], "}"),
paste0("\\cellcolor[HTML]{FF0600}{", df[, var], "}"))
}
Flag$Overall <- color_cells(df = Flag, var= "Overall")
Flag$DC_Info <- color_cells(df = Flag, var= "DC_Info")
Flag$Care_Trans <- color_cells(df = Flag, var= "Care_Trans")
@
<<results=tex>>=
Flagx <- xtable(Flag)
align(Flagx) <- "|c|l|l|c|c|c|"
print(Flagx[1:40,], hline.after=c(-1:40), sanitize.text.function=identity,
sanitize.colnames.function = Hmisc::latexTranslate)
@