-
DescriptionDescriptionHello, I am doing some project at company. But It seems that it is not easy to properly use Python with many cross-references, especially for sub captions both in making multiple tables and plots. So, I decided to use R. My question is how to render multiple tables with subcaptions using kable() and a for loop? It seems that there is no function like display() of Python in R. For example, ---
format: html
engine: knitr
execute:
warning: false
---
```{r}
rm(list=ls())
library(tidyverse)
library(knitr)
```
```{r working}
#| label: tbl-mtcars2
#| tbl-cap: "Mtcars Data"
#| tbl-subcap:
#| - "A"
#| - "B"
#| - "C"
#| - "D"
#| - "E"
#| - "F"
mtcars %>% filter(mtcars$carb==unique(mtcars$carb)[1]) %>%kable()
mtcars %>% filter(mtcars$carb==unique(mtcars$carb)[2]) %>%kable()
mtcars %>% filter(mtcars$carb==unique(mtcars$carb)[3]) %>%kable()
mtcars %>% filter(mtcars$carb==unique(mtcars$carb)[4]) %>%kable()
mtcars %>% filter(mtcars$carb==unique(mtcars$carb)[5]) %>%kable()
mtcars %>% filter(mtcars$carb==unique(mtcars$carb)[6]) %>%kable()
```
```{r not_working}
#| label: tbl-mtcars
#| tbl-cap: "Mtcars Data"
#| tbl-subcap:
#| - "A"
#| - "B"
#| - "C"
#| - "D"
#| - "E"
#| - "F"
temp_function<-function(i){
temp=mtcars %>% filter(mtcars$carb==unique(mtcars$carb)[i])
return(kable(temp))
}
for (i in 1:6){
temp_function(i)
}
# or
for (i in 1:6){
temp=mtcars %>% filter(mtcars$carb==unique(mtcars$carb)[i])
kable(temp)
}
```
Output |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The following blog post should answer this: https://mickael.canouil.fr/posts/2023-03-05-quarto-auto-table-crossref/. |
Beta Was this translation helpful? Give feedback.
-
Hello @mcanouil, I forgot to reply to your answer. |
Beta Was this translation helpful? Give feedback.
The following blog post should answer this: https://mickael.canouil.fr/posts/2023-03-05-quarto-auto-table-crossref/.