only knit rmd files to md if they have changed
[rnaseq-cwl-training.git] / bin / generate_md_episodes.R
index 6c27d9c9245fc5b6d1c5aaa82af2ea4073e59b80..60d65e970be608b571e7a47e74e966f6aee7dd2a 100644 (file)
@@ -24,15 +24,18 @@ generate_md_episodes <- function() {
         install.packages(missing_pkgs)
     }
 
-    ## find all the Rmd files, and generate the paths for their respective outputs
-    src_rmd <- list.files(pattern = "??-*.Rmd$", path = "_episodes_rmd", full.names = TRUE)
-    dest_md <- file.path("_episodes", gsub("Rmd$", "md", basename(src_rmd)))
+    ## 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]
+
     ## knit the Rmd into markdown
-    mapply(function(x, y) {
-        knitr::knit(x, output = y)
-    }, src_rmd, dest_md)
-    
+    knitr::knit(src_rmd, output = dest_md)
+
     # Read the generated md files and add comments advising not to edit them
     vapply(dest_md, function(y) {
       con <- file(y)