Created
October 18, 2018 18:03
-
-
Save turgeonmaxime/7ab6e22b3a4191e31def2e42b7e69130 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
# Loop through list of departments | |
list_depts <- c("Adult Medicine", | |
"Heart Health", | |
"Maternal Services") | |
for (dept in list_depts) { | |
# Add underscores | |
dept_f <- stringr::str_replace_all(dept, " ", "_") | |
# Change the name of output | |
output <- "report_template.Rmd" %>% | |
str_replace("template", dept_f) %>% | |
str_replace("Rmd", "pdf") | |
# Render custom report | |
rmarkdown::render("report_template.Rmd", | |
params = list( | |
department = dept | |
), | |
output_file = output) | |
} |
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
--- | |
title: "`r paste0('Survey Results--', params$org)`" | |
author: | |
name: "Maxime Turgeon" | |
date: "`r format(Sys.Date(), format = '%B %e, %Y')`" | |
output: html_document | |
params: | |
department: Adult Medicine | |
--- | |
```{r setup, include=FALSE, message = FALSE} | |
knitr::opts_chunk$set(echo = FALSE) | |
# list required pacakges | |
library(tidyverse) | |
library(lubridate) | |
library(glue) | |
``` | |
```{r data} | |
# Generate fake data | |
date <- ymd("2018-01-01") + months(0:11) | |
metric <- rnorm(length(date), mean = 7.5, sd = 2) | |
``` | |
```{r plot} | |
# Plot results | |
tibble(date, metric) %>% | |
ggplot(aes(x = date, y = metric)) + | |
geom_line() + | |
geom_point() + | |
expand_limits(y = 0) + | |
theme_minimal() + | |
ggtitle(glue("Metric results for {params$department}")) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run the code above, you need to have both files in the same directory (or update the input/output paths). Then simply source the R script and voila!