Skip to content

Instantly share code, notes, and snippets.

@edgararuiz
Created February 15, 2024 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edgararuiz/1dca815ab592702de4571b3e023ef3c6 to your computer and use it in GitHub Desktop.
Save edgararuiz/1dca815ab592702de4571b3e023ef3c6 to your computer and use it in GitHub Desktop.
Dynamic code chunks
```{r setup, include = FALSE}
suppressPackageStartupMessages(library(tidyverse))
suppressPackageStartupMessages(library(rlang))
```
```{r, echo = FALSE, results='asis'}
walk(
names(mtcars),
~{
curr_var <- .x
x <- knitr::knit_child("plot.Rmd", envir = environment(), quiet = TRUE)
cat(x, sep = '\n')
}
)
```
## `r paste0(curr_var, " vs mpg")`
```{r, echo = FALSE}
mtcars %>%
ggplot() +
geom_point(aes(x = mpg, y = !! parse_expr(curr_var)))
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment