Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save StevenMMortimer/e54ec050d97d79996189 to your computer and use it in GitHub Desktop.
Save StevenMMortimer/e54ec050d97d79996189 to your computer and use it in GitHub Desktop.
Automate Chunks of Analysis in R Markdown
========================================================
```{r setup, echo=FALSE}
library(knitr)
library(DT)
```
```{r create-datasets, echo=FALSE}
datasets <- list(iris[1:50,],iris[51:100,],iris[101:150,])
```
```{r create-markdown-chunks-dynamically, include=FALSE}
out = NULL
for (i in 1:3) {
knit_expanded <- paste0("\n```{r results='asis', echo=FALSE}\n\ndatatable(datasets[[", i, "]])\n\n```")
out = c(out, knit_expanded)
}
```
<!--- knit those table chunk statements -->
`r paste(knit(text = out), collapse = '\n')`
@Sopwith
Copy link

Sopwith commented Jun 23, 2020

Hey, this is really cool. Now I can finally make a set of dynamic tabsets with DTs on them. Thanks for posting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment