Search code examples
rmarkdownknitrr-markdownsweave

How can I print an R macro in Markdown in colour?


I have a print statement in R as a macro in Markdown

```{r chunk_name, echo=FALSE}
if ( any(so.results$Duration <0.0))
{print("there are non-positive  durations")
} else
{print("all  durations are fine!")}
```

and I want to generate a PDF, not an XML! How can I print "all durations are fine!" in colour for example green or red?


Solution

  • Using HERE and HERE and the hints given by User I wrote the following:

     ```{r, results='asis', echo=FALSE}
     if ( any(so.results$Duration <0.0)) 
      {cat("\n") print("\textcolor{blue}
       {print("there are non-positive durations}") 
    } else 
    {cat("\n") print("\textcolor{red}{print("all durations are fine!}")}
     ```
    

    which solves the problem.