Search code examples
rr-exams

How to name html files produced by nops_eval with the students ID?


I am aware that nops_eval creates folders named with students' ID, and inside each of those folders, an HTML file (with the same name for all students) is created. I would like to have the HTML files with the students' ID or the students' names. It would be necessary to have a folder per student, just the HTML files all in the same folder, without Is it possible? The code used:

eval <- nops_eval(register = "register_df.csv",
          solutions = "solutions.rds",
          scans = "nops_scan.zip",
          language = "pt",
          eval = exams_eval(partial = F, negative = -0.25, rule = "false"),
          dir = "eval",
          interactive = T,
          mark = F)

Solution

  • Recently, in version 2.4-0 nops_eval() gained the option to plug in custom writers for the evaluation results. So, in principle, this could be used. However, if the focus is just to rename the HTML files, I would probably simply unzip() the ZIP file, file.rename() the HTML files, and then file.remove() the previous directories.

    For me on Linux this works:

    f <- unzip("nops_eval.zip")
    id <- strsplit(f, "/", fixed = TRUE)
    id <- sapply(id, function(x) x[length(x) - 1])
    for(i in seq_along(id)) {
      file.rename(f[i], paste0(id[i], ".html"))
      file.remove(id[i])
    }
    

    Note: Possibly, the file paths in f are separated with a backslash rather than a slash on Windows. If so, you would have to replace "/" with "\\" in the strsplit() call.