I have a R Markdown child-file, which should produce different output based on a R-condition .
My code (sorry it is not reproducible):
{r results='asis', echo = FALSE}
if (class(robject) == "character") {
cat("**R object is empty!**") # This text should appear in RED in the Output (HTML) file.
} else {
cat("### Data columns\n")
cat("\n")
kable(robject)
cat("\n")
}
What the code does:
If my robject
is not a data.frame
it is set to an empty string (robject <- ""
). With this "trick" it is possible to if_else
about robject
.
In my R Markdown file it should be printed either "R object is empty!" or a summary of the dataset (which is a data.frame
again). If the dataset is empty, the text should appear in RED!
Two questions:
How to print the text in RED (or every other color) using the
cat
command as in the example above? (I triedtext_spec
fromkableextra
as mentioned here, I triedcrayron
-Package as well and I tried to enter html_tags withprint/cat
. Neither worked!)Maybe it is better to if else outside the R Chunk. Unfortunately this approach did not work either enter link description here
Thank you for any help.
If you need some further information, please ask me for it. Thanks!