I want to output datatable several times using for loop on Rmarkdown.
test.Rmd
---
title: "test"
output: pdf_document
---
```{r, include=TRUE, echo=FALSE, comment=NA, results='asis'}
library(DT)
n <- 1
for (i in 1:3) {
dat <- cars[n,]
DT::datatable(dat)
n <- n + 1
}
```
This code does not print the datatable. I want to do something like the following code in a for loop.
test.Rmd
---
title: "test"
output: pdf_document
---
```{r, include=TRUE, echo=FALSE, comment=NA, results='asis'}
library(DT)
dat <- cars[1,]
DT::datatable(dat)
dat <- cars[2,]
DT::datatable(dat)
dat <- cars[3,]
DT::datatable(dat)
```
Do you know why the for loop does not work? Thank you