knitr::opts_chunk$set(echo = TRUE, eval=F)
library(drake)
library(econDV)
library(dplyr)

makecondition

library(drake)
library(rmd2drake)
library(dplyr)
library(googleclassroom)
library(readr)
# library(rmdgrader)
library(purrr)
library(rlang)
library(testthat)
library(withr)
rprojroot::is_rstudio_project$make_fix_file() -> .root
.root <- function(){
  "/Users/martinl/Github/course-dashboard-programming-for-data-science"
}
problemFolder <-
  file.path(.root(), params$submissionFolder, params$title,
            "problem")

Process

# initiate process instance

process <- Process()

# get list of code chunks
undebug(process$correctAnsFilename$tryGet_list_codeChunks)
process$correctAnsFilename$tryGet_list_codeChunks()
process$inBatch_studentsRmds$tryGet_list_codeChunks()

# If one Rmd content changed, you can update simply that student's respective elements in process instance like:
# process$studentsRmds$HW8_410672033.Rmd$tryGet_list_codeChunks()

Evaluate

After users get list_codeChunks from all Rmd files, it's time to evaluate these codes.

# Initiate an Evaluation Instance
undebug(Evaluate)
ei <- Evaluate(process)

# resolve codes in batch
ei$answerValues$batch$resolve$part1()
ei$answerValues$batch$resolve$part2()

# once resolved, answer values will show up for all Rmds such as:
undebug(ei$answerValues$Final_410774205.Rmd$resolve$part1)
ei$answerValues$Final_410774205.Rmd$resolve$part1()
names(ei$answerValues)[-1] -> allNames
count <- 0
for(.x in ei$answerValues[-1]){
  count <- count + 1
  cat(allNames[[count]], '\n\n')
  .x$resolve$part1()
}
file.edit(process$studentsRmds$Final_410973017.Rmd$filename)

Final_410973017.Rmd 
process$file.edit$HW7_410874206.Rmd()
process$studentsRmds$HW7_410874206.Rmd$move2problem()

when screwed

Sometimes students throwed in, say totally wrong Rmd, it can break down batch evaluation. In this case, run the follow example code (which uses part4) as an example.

for(.it in seq_along(ei$allRmds)){
  cat(glue::glue('{ei$allRmds[[.it]]}\n\n'))
  ei$answerValues[[ei$allRmds[[.it]]]]$resolve$part1()
}

The loop stops at where the problem from, say Final_410973013.Rmd Then you can use the move2problem method to remove it. Just remember to do .nullify after each removal.

process$file.edit$Final_410973013.Rmd()
process$studentsRmds$Final_410973013.Rmd$move2problem()
process$.nullify()

Once done, you can restart a new Evaluation instance (no need to start from Process stage).

process is actually equip with file.edit method. Use it like:

process$file.edit$HW7_410672056.Rmd()

individually

# You can also evaluate each Rmd codes one-by-one via their own resolve method. Once resolved, you can see the values after resolution
ei$answerValues$`homework7-ans.Rmd`$resolve$part4()
ei$answerValues$`homework7-ans.Rmd`$resolve$part5()
ei$answerValues$`homework7-ans.Rmd`$resolve$part6()
View(ei$answerValues$`homework7-ans.Rmd`$values)

Save

You only save necessary answer values for grading step via save method.

filename=file.path(.root(), params$gradingFolder, 
                    params$title, "data4step3.Rdata")

ei$save(filename = filename
          )


tpemartin/rmdgrader documentation built on Nov. 22, 2022, 6:39 p.m.