Skip to content

Instantly share code, notes, and snippets.

@BartlettJE
Last active March 20, 2025 14:23
Show Gist options
  • Select an option

  • Save BartlettJE/6c67083e8686f8dcb01c4a2e699c6e36 to your computer and use it in GitHub Desktop.

Select an option

Save BartlettJE/6c67083e8686f8dcb01c4a2e699c6e36 to your computer and use it in GitHub Desktop.
We wanted to create a series of .Rmd files based on a spreadsheet. This will be passed to a Quarto book/blog, but we wanted to generate entries based on responses to an online form. It took a surprising amount of time to find solutions to creating .Rmd files, not just creating dynamic reports or knitting multiple .Rmd files.
library(glue)
library(tidyverse)
library(readxl)
# load form of terms and definitions
# dat <- read_xlsx("terms.xlsx")
# for reproducibility, you can test it on a generated version
dat <- tibble(file_name = c("sotl","impact"),
term = c("SoTL", "Impact"),
short_def = c("A scholarly approach to teaching",
"The demonstable contribution of research."),
long_def = c("SoTL, or the Scholarship of Teaching and Learning, is a scholarly approach to teaching that involves systematically examining one's own teaching practices and student learning to improve both, often with the goal of making findings public to contribute to the wider teaching community.",
"The demonstrable contribution that excellent research makes to society and the economy."))
# function to create a .Rmd file by adding in terms and definitions
make_entry <- function(dat){
# for each entry, use glue to add the term, short definition, and long definition
entry <- glue("
## {dat$term}
<dfn>{dat$short_def}</dfn>
{dat$long_def}
")
# create a unique file name for each term
file_name <- paste0("dat$file_name, ".Rmd")
# add the template and save
cat(entry,
file = file_name)
}
# we want to create a .Rmd for each term with a static format
# so add the terms for each row of the spreadsheet and create a .Rmd for each one
for (i in 1:nrow(dat)){
make_entry(dat[i, ])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment