RMarkdown 在一个块中编号多个 figures/tables

RMarkdown numbering multiple figures/tables in one chunk

我的 RMarkdown 文档包含从一个块中生成多个图形或 table 的代码块。例如,它循环遍历一堆变量,为每个变量生成摘要统计信息 tables。问题是当我试图生成一个 HTML 文档时,这些 figures/tables 的编号经常是错误的;当我编译 PDF 时,不会发生这个问题。问题是从同一个块生成的所有 table 都会得到相同的 table 数字。

这是一个例子:

---
title: "Testing Section Numbers"
author: "Authors"
date: "January 2019"
output:
  bookdown::gitbook:
    number_sections: yes
editor_options:
  chunk_output_type: console
---

# R Markdown

Text text text 

```{r pressure1, echo=FALSE, fig.cap=c("This is my plot", "This is my other plot")}
plot(pressure)

plot(iris)
```

```{r pressure2, echo=FALSE}
library(knitr)
kable(pressure, caption = "My first table")
kable(pressure, caption = "My second table")
```

这是由于 knitr 的错误,I just fixed in the development version 在 Github 上。请尝试

remotes::install_github('yihui/knitr')