Skip to content
Sean Kross edited this page Apr 11, 2016 · 1 revision

Find all answer test names:

library(yaml)
library(stringr)

path <- "~/swirl_courses"
courses <- c("Exploratory_Data_Analysis",
             "Getting_and_Cleaning_Data",
             "R_Programming",
             "Regression_Models",
             "Statistical_Inference")

lessons <- list.files(file.path(path, courses), 
                      recursive = TRUE, pattern = "lesson", 
                      full.names = TRUE)

tests <- list()
index <- 1
for(i in lessons){
  lesson <- yaml.load_file(i)  
  for(q in 1:length(lesson)){
    anstest <- lesson[[q]][["AnswerTests"]]
    if(!is.null(anstest)){
      tests[[index]] <- str_extract(anstest, "^[^\\(]+")
      index <- index + 1
    }
  }
}
Clone this wiki locally