Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RMarkdown numbering multiple figures/tables in one chunk

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")
```
like image 373
yaleeconjournal Avatar asked Nov 07 '22 22:11

yaleeconjournal


1 Answers

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')
like image 91
Yihui Xie Avatar answered Nov 15 '22 13:11

Yihui Xie