r-markdown - 在 rmarkdown 中循环标题/部分?
问题描述
我正在尝试生成一个带有部分/标题的循环,后面跟着一个 rmarkdown 中的数字。我知道我可以使用 cat("## xyz") 在我的块中生成一个新标头,但我观察到一些奇怪的行为。
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F)
```
Version 1: (does not work)
```{r, results='asis'}
for (i in 1:5) {
cat("\n")
cat("## This is a heading for ", i, "\n")
plot(pressure)
cat("\n")
}
```
Version 2: (does not work)
```{r, results='asis'}
for (i in 1:5) {
cat("\n")
cat("## This is a heading for ", i, "\n")
plot(pressure)
cat("\n")
plot(pressure)
cat("\n")
}
```
Version 3 (works):
```{r, results='asis'}
for (i in 1:5) {
cat("\n")
cat("## This is a heading for ", i, "\n")
plot(cars)
cat("\n")
plot(pressure)
cat("\n")
}
```
我希望输出是
标题 1
图1
标题 2
图 2
标题 3
图 3
等等
解决方案
推荐阅读
- hibernate - 使用 Spring boot 时的两个版本的 Hibernate
- docker - 连接到远程 Docker 守护进程
- facebook - 使用 Facebook graph api 的网站加载速度非常慢
- hadoop - hadoop 3.1.2 ./start-all.sh 错误,意外标记 `<' 附近的语法错误
- npm - Gulp 4 任务未与并行/串行同步运行
- typescript - 如何从嵌套对象中选择类型?
- scala - 根据scala中的条件替换属性的值
- bash - Openvpn领先——从txt用户名和密码解析错误
- html - 获取任何 Facebook 页面的页面 id
- azure-devops - 使用 Azure Devops Pipeline 将 AAD 组添加到 SQL Azure