- ## where the Rmd files and the datasets are located
- rmd_path <- "_episodes_rmd"
- rmd_data <- file.path(rmd_path, "data")
-
- ## where the markdown files and the datasets will end up
- dest_path <- "_episodes"
- dest_data <- file.path(dest_path, "data")
-
- ## find all the Rmd files, and generates the paths for their respective outputs
- src_rmd <- list.files(pattern = "??-*.Rmd$", path = rmd_path, full.names = TRUE)
- dest_md <- file.path(dest_path, gsub("Rmd$", "md", basename(src_rmd)))
+ if (require("checkpoint") && packageVersion("checkpoint") >= '0.4.0') {
+ required_pkgs <-
+ checkpoint:::scanForPackages(project = "_episodes_rmd",
+ verbose=FALSE, use.knitr = TRUE)$pkgs
+ } else {
+ stop("The checkpoint package (>= 0.4.0) is required to build the lessons.")
+ }
+
+ missing_pkgs <- required_pkgs[!(required_pkgs %in% rownames(installed.packages()))]
+
+ if (length(missing_pkgs)) {
+ message("Installing missing required packages: ",
+ paste(missing_pkgs, collapse=", "))
+ install.packages(missing_pkgs)
+ }
+
+ ## get the Rmd file to process from the command line, and generate the path for their respective outputs
+ args <- commandArgs(trailingOnly = TRUE)
+ if (length(args) != 2){
+ stop("input and output file must be passed to the script")
+ }
+
+ src_rmd <- args[1]
+ dest_md <- args[2]