In RMarkdown is there a way to specify the font color?
There doesn\'t seem to be an option while browsing through the chunk options
I basically used Nicholas Hamilton's answer but because I used xtable
and print
, I had some problems with certain latex sequences being escaped. Namely, \\textcolor
being transformed to $\backslash$textcolor
. I was able to get it right by avoiding sanitizing in the following way:
```{r results='asis'}
tbl = data.frame(a = letters[1:10], b = 1:10 / 10)
tbl$b = ifelse(tbl$b < 0.5, colFmt(tbl$b, "red"), colFmt(tbl$b, "green"))
print(xtable(tbl), sanitize.text.function = identity)
```
I then had to go and manually sanitize a few characters like %
but at least \textcolor
was correctly applied. Of course, this could be avoided by expanding your own sanitize function.