5
votes

My RMarkdown document has code chunks that generate multiple figures or tables from within one chunk. For instance, it loops through a bunch of variables to generate summary statistics tables for each variable. The problem is that the numbering of these figures/tables is often wrong when I try to generate a HTML document; this problem doesn't happen when I compile a PDF. The problem is that all the tables generated from the same chunk would get the same table number.

Here is an example:

---
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")
```
1

1 Answers

1
votes

This is due to a bug of knitr, which I just fixed in the development version on Github. Please try

remotes::install_github('yihui/knitr')