-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_presenter_notes.R
38 lines (29 loc) · 1.03 KB
/
extract_presenter_notes.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
library(stringr)
library(purrr)
library(dplyr)
yaml_header <- readLines("presenter_notes_yaml_header.txt")
webinar_lines <- readLines("ipumsr_webinar.Rmd") %>%
paste0(collapse = "\n") %>%
str_split("\n---\\s*\n") %>%
.[[1]] %>%
str_trim()
webinar_slides <- tibble(raw = webinar_lines)
introduction_notes <- readLines("introduction.txt") %>%
paste0(collapse = "\n")
presenter_notes <- webinar_slides %>%
mutate(
heading = str_match(raw, "((?<!#)# .+?)(?:$|\n)")[, 2], # "(?:...)" makes a "non-capturing group"
notes = str_split_fixed(raw, "\\?\\?\\?\n+", n = 2)[, 2]
) %>%
mutate(
heading = if_else(is.na(heading), "# NO HEADING", heading),
heading = paste0(heading, " (", row_number(), ")"),
notes = if_else(row_number() == 1, introduction_notes, notes),
heading_plus_notes = paste0(heading, "\n\n", notes, "\n\n")
) %>%
pull(heading_plus_notes)
writeLines(
c(yaml_header, "\n", presenter_notes),
"ipumsr_webinar_presenter_notes.Rmd"
)
rmarkdown::render("ipumsr_webinar_presenter_notes.Rmd")