Last active
April 21, 2021 09:13
-
-
Save ChrisBeeley/1a84301a9329aeb7dd9a9cf2ff95f62c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
--- | |
title: "Loop demo" | |
author: "Chris Beeley" | |
date: "21/04/2021" | |
output: html_document | |
params: | |
species: NA | |
--- | |
```{r setup, include=FALSE} | |
library(palmerpenguins) | |
library(tidyverse) | |
knitr::opts_chunk$set(echo = TRUE) | |
``` | |
## `r params$species` | |
```{r} | |
penguins %>% | |
filter(species == params$species) %>% | |
ggplot(aes(x = bill_length_mm)) + geom_density() | |
``` |
This file contains hidden or 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
--- | |
title: "Loop variables" | |
author: "Chris Beeley" | |
date: "21/04/2021" | |
output: html_document | |
params: | |
variable: NA | |
--- | |
```{r setup, include=FALSE} | |
library(palmerpenguins) | |
library(tidyverse) | |
knitr::opts_chunk$set(echo = TRUE) | |
``` | |
## `r params$variable` | |
```{r} | |
penguins %>% | |
ggplot(aes(x = .data[[params$variable]])) + geom_density() | |
``` |
This file contains hidden or 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
# install.packages("palmerpenguins") | |
library(rmarkdown) | |
library(palmerpenguins) | |
# loop rows | |
for(i in unique(penguins$species)){ | |
render("loop_penguins.Rmd", params = list(species = i), | |
output_file = paste0("report_", i)) | |
} | |
# loop columns | |
for(i in c("bill_length_mm", "bill_depth_mm")){ | |
render("loop_variables.Rmd", params = list(variable = i), | |
output_file = paste0("variable_report_", i)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment