[英]Processing Rmarkdown inside chunks
I would like to add a formatted section to a knitr markdown report conditional on some parameters. 我想以某些参数为条件,将格式化的部分添加到针织降价报告中。
Eg, 例如,
```{r conditional, eval=outliers, result="asis"}
# If outliers==TRUE, the following section is added to the report
print(
"# Conditional section
## Subsection
This is here because **outliers==TRUE**!")
```
Of course, the above doesn't work at all. 当然,以上根本不起作用。 How can I modify it so that it does?
我如何修改它才能做到?
You're very close already. 您已经很亲密了。 You need to use
cat
instead of print
. 您需要使用
cat
而不是print
。 You will also want to change how you supply your string. 您还将需要更改提供字符串的方式。 Your section headings won't render with white space in front of them.
您的部分标题不会在其前面带有空白。
---
title: "Untitled"
output: html_document
---
```{r}
outliers <- TRUE
```
```{r conditional, eval=outliers, results="asis"}
# If outliers==TRUE, the following section is added to the report
cat(
"# Conditional section
## Subsection
This is here because **outliers==TRUE**!")
```
Or alternatively 或者
---
title: "Untitled"
output: html_document
---
```{r}
outliers <- TRUE
```
```{r conditional, eval=outliers, results="asis"}
# If outliers==TRUE, the following section is added to the report
cat(
"# Conditional section ",
"## Subsection ",
"This is here because **outliers==TRUE**!",
sep = "\n")
```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.