Skip to contents

Records one attempt and returns a gradethis graded result. This helper is intended for explicit use inside a gradethis::grade_this() check chunk in a learnr tutorial. It does not intercept learnr submissions automatically.

Usage

track_gradethis_attempt(
  con,
  student_id,
  tutorial_id,
  question_id,
  submitted_answer,
  correct,
  feedback = NULL,
  score = NULL,
  max_score = 1,
  grade_status = NULL,
  session_id = NULL,
  attempt_number = NULL,
  timestamp = Sys.time(),
  context = NULL
)

Arguments

con

A DBI connection.

student_id

Student identifier.

tutorial_id

Tutorial identifier.

question_id

Question identifier.

submitted_answer

Submitted answer or code. In a grade_this() check, this is usually .user_code.

correct

Logical scalar indicating whether the submission is correct.

feedback

Feedback returned to the learner and stored in the database. If NULL, a simple default message is chosen from correct.

score

Numeric score to store. If NULL, stores max_score when correct = TRUE and 0 otherwise.

max_score

Numeric maximum score. Defaults to 1.

grade_status

Character status to store. If NULL, stores "correct" when correct = TRUE and "incorrect" otherwise.

session_id

Optional session identifier passed to track_attempt().

attempt_number

Optional attempt number passed to track_attempt().

timestamp

Attempt timestamp. Defaults to Sys.time().

context

Optional context returned by setup_learnr_tracking(). If supplied, student_id, tutorial_id, and the database connection can be resolved from the context.

Value

A gradethis_graded object returned by gradethis::graded().

Examples

if (requireNamespace("gradethis", quietly = TRUE)) {
  db_path <- tempfile(fileext = ".sqlite")
  con <- init_tracking_db(db_path, overwrite = TRUE)

  track_gradethis_attempt(
    con = con,
    student_id = "student_001",
    tutorial_id = "module_01",
    question_id = "q1",
    submitted_answer = "2 + 2",
    correct = TRUE,
    feedback = "Correct."
  )

  DBI::dbDisconnect(con)

  tracking <- setup_learnr_tracking(
    tutorial_id = "module_01",
    student_id = "student_001",
    db_path = db_path
  )

  track_gradethis_attempt(
    context = tracking,
    question_id = "q2",
    submitted_answer = "mean(x)",
    correct = FALSE
  )
}
#> <gradethis_graded: [Incorrect] Incorrect.>