1 generate_md_episodes <- function() {
3 if (require("knitr") && packageVersion("knitr") < '1.9.19') {
4 stop("knitr must be version 1.9.20 or higher")
5 } else stop("knitr 1.9.20 or above is needed to build the lessons.")
7 if (!require("stringr"))
8 stop("The package stringr is required for generating the lessons.")
10 if (require("checkpoint")) {
12 checkpoint:::projectScanPackages(project = "_episodes_rmd",
13 verbose=FALSE, use.knitr = TRUE)$pkgs
15 stop("The checkpoint package is required to build the lessons.")
18 missing_pkgs <- required_pkgs[!(required_pkgs %in% rownames(installed.packages()))]
20 if (length(missing_pkgs)) {
21 message("Installing missing required packages: ",
22 paste(missing_pkgs, collapse=", "))
23 install.packages(missing_pkgs)
26 ## find all the Rmd files, and generates the paths for their respective outputs
27 src_rmd <- list.files(pattern = "??-*.Rmd$", path = "_episodes_rmd", full.names = TRUE)
28 dest_md <- file.path("_episodes", gsub("Rmd$", "md", basename(src_rmd)))
30 ## knit the Rmd into markdown
31 mapply(function(x, y) {
32 knitr::knit(x, output = y)
37 generate_md_episodes()