Skip to contents

Assume three of your students submitted their homework. One student didn’t complete the questions, a second student submitted only wrong answers, and a third student answered all questions correctly:

student_answers_no_answers <- list(
  Q1 = NULL, 
  Q2 = NULL, 
  Q3 = NULL,
  Q4 = NULL
)

student_answers_wrong <- list(
  Q1 = c(1:3), 
  Q2 = c(1:10), 
  Q3 = data.frame(1:2),
  Q4 = NULL
)

student_answers_right <- list(
  Q1 = c(1:5), 
  Q2 = c(6:10), 
  Q3 = data.frame(X=1:5, A = rnorm(5), b = rnorm(5)),
  Q4 = 'test'
)

Q1 = c(1:5)
Q2 = c(6:10)
Q3 = data.frame(X=1:5, A = rnorm(5), b = rnorm(5))
Q4 = 'test'

The instructor created their own autoautogradeR to grade these questions.. The autoautogradeR is a list of lists. The first level of the list will have as many elements as questions to grade. Each nested list contains only two elements. The first element is the correct answer. The second is the function that is used to transform the student’s answer into a compatible answer.

.reference_answers <- list(
  Q1 = list(digest(Q1, algo = 'sha1'), fun = function(x){digest(x, algo = 'sha1')}), # Question 1
  Q2 = list(length(Q2), fun = function(x){length(x)}),                               # Question 2
  Q3 = list(dim(Q3), fun = function(x){dim(x)}),                                     # Question 3
  Q4 = list(Q4, fun = function(x){!is.null(x)})                                      # Question 4
)

Let’s now grade the submissions using autogradeR:

gradeR(student_answers = student_answers_no_answers, reference_answers = .reference_answers, maximum_grade=10)
#> ❓ Question Q1 - Incomplete
#> ❓ Question Q2 - Incomplete
#> ❓ Question Q3 - Incomplete
#> ❓ Question Q4 - Incomplete
#> 
#> 
#>    ⌛ Auto-grade 0 %,  0 / 10 points
gradeR(student_answers = student_answers_wrong, reference_answers = .reference_answers, maximum_grade=10)
#> ❌ Question Q1 - Potentially incorrect
#> ❌ Question Q2 - Potentially incorrect
#> ❌ Question Q3 - Potentially incorrect
#> ❓ Question Q4 - Incomplete
#> 
#> 
#>    ⌛ Auto-grade 0 %,  0 / 10 points
gradeR(student_answers = student_answers_right, reference_answers = .reference_answers, maximum_grade=10)
#> ✅ Question Q1 - Correct!
#> ✅ Question Q2 - Correct!
#> ✅ Question Q3 - Correct!
#> ✅ Question Q4 - Correct!
#> 
#> 
#>    ⌛ Auto-grade 100 %,  10 / 10 points