1 generate_md_episodes <- function() {
3 if (require("knitr")) {
4 if (packageVersion("knitr") < '1.9.19') {
5 stop("knitr must be version 1.9.20 or higher")
7 } else stop("knitr 1.9.20 or above is needed to build the lessons.")
9 if (!require("stringr"))
10 stop("The package stringr is required for generating the lessons.")
12 ## where the Rmd files and the datasets are located
13 rmd_path <- "_episodes_rmd"
14 rmd_data <- file.path(rmd_path, "data")
16 ## where the markdown files and the datasets will end up
17 dest_path <- "_episodes"
18 dest_data <- file.path(dest_path, "data")
20 ## find all the Rmd files, and generates the paths for their respective outputs
21 src_rmd <- list.files(pattern = "??-*.Rmd$", path = rmd_path, full.names = TRUE)
22 dest_md <- file.path(dest_path, gsub("Rmd$", "md", basename(src_rmd)))
24 ## knit the Rmd into markdown
25 mapply(function(x, y) {
26 knitr::knit(x, output = y)
30 ## copy the datasets from _episodes_rmd/data to _episodes/data
31 rmd_data_files <- list.files(path = rmd_data, full.names = TRUE)
32 dest_data_files <- file.path(dest_data, basename(rmd_data_files))
34 if (!dir.exists(file.path(dest_data)))
35 dir.create(file.path(dest_data))
37 apply(cbind(rmd_data_files, dest_data_files), 1,
38 function(x) file.copy(x[1], x[2]))
41 generate_md_episodes()