如何在 Markdown 中以彩色打印 R 宏?
How can I print an R macro in Markdown in colour?
我在 R
中有一个打印语句作为 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!")}
```
我想生成 PDF,而不是 XML!如何打印 "all durations are fine!"
颜色,例如绿色或红色?
使用 HERE and HERE and the hints given by User 我写了以下内容:
```{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!}")}
```
这解决了问题。
我在 R
中有一个打印语句作为 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!")}
```
我想生成 PDF,而不是 XML!如何打印 "all durations are fine!"
颜色,例如绿色或红色?
使用 HERE and HERE and the hints given by User 我写了以下内容:
```{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!}")}
```
这解决了问题。