R/start_grading.R

Defines functions start_grading

Documented in start_grading

#' Extract and render notebooks, then create a gradesheet for them.
#'
#' @param archive The file archive to extract the notebooks from.
#' @param course_name The name of the course to extract the notebooks from.
#' @param quiz_name The name of the quiz to extract.
#' @param output_dir A path to write the output files to (it will be
#'   created if it does not exist).
#' @param exclude A character vector of usernames to exclude from processing.
#' @param invert_exclusions Invert the pattern matching triggered by `exclude`,
#'   essentially turning "exclude" into "keep only".
#'
#' @export
start_grading <- function(
  archive,
  course_name,
  quiz_name,
  output_dir,
  exclude = NULL,
  invert_exclusions = FALSE
) {
  nb_files <- extract_and_render(
    archive, course_name, quiz_name,
    output_dir,
    exclude, invert_exclusions
  )

  gs_file <- nb_files[[1]] %>%
    fs::path_dir() %>% fs::path_dir() %>%
    fs::path(glue::glue('grades_{quiz_name}.csv'))

  create_grade_sheet(nb_files, gs_file)

  prompt <- 'Would you like to open the output folder? [y/n] '
  if ('y' == stringr::str_to_lower(readline(prompt))) {
    dir <- fs::path_dir(gs_file)
    if (.Platform['OS.type'] == "windows") {
      shell.exec(dir)
    } else {
      system(paste(Sys.getenv("R_BROWSER"), dir))
    }
  }
}
adamblake/nbsimplegrader_companion documentation built on April 19, 2020, 6:05 p.m.