Last active
April 2, 2023 14:48
-
-
Save StevenMMortimer/e54ec050d97d79996189 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, this is really cool. Now I can finally make a set of dynamic tabsets with DTs on them. Thanks for posting.