4

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

Tim Ikata
  • 201
  • 1
  • 7
  • 5
    Does this answer your question? [Using \`ggplotly\` and \`DT\` from a \`for\` loop in Rmarkdown](https://stackoverflow.com/questions/60685631/using-ggplotly-and-dt-from-a-for-loop-in-rmarkdown) – stefan Jun 29 '20 at 05:19
  • This is what I was looking for. Thank you! – Tim Ikata Jun 29 '20 at 10:24

0 Answers0