library(learnr)
library(submitr)
library(gradethis)
library(tidyverse)

knitr::opts_chunk$set(echo = FALSE)
options(tutorial.storage = "none")
knitr::opts_chunk$set(exercise.checker = gradethis::grade_learnr)

Intro

The first thing you have to do is to log in.

instructor_key <- "isostats"
account_name <- "statprep.annie@gmail.com"
credentials <- 
  "password.csv"
 # "1WvQDD1sQHcc_aZ1eisWkZvhU4a3jEAR2HXt_1REojpM"

storage_actions <- in_local_file("submissions.csv")

Continue

Click on Next topic to start.

Short text answers

Overview

If you'd like users to submit open-ended answers, use a text box question. Correct and incorrect answers will be matched exactly (including white space). A minimum of one correct answer is required.

Text value inputs are trimmed before they are compared to answers provided.

Here a custum question_is_correct function is used

question_is_correct.always_correct <- function(question, value, ...) {
    return(learnr::mark_as(TRUE, NULL))
}

question(
  "Provide your answer",
  answer("answer", correct = TRUE),
  correct = "Answer Provided",
  allow_retry = TRUE,
  type = c("always_correct", "learnr_text")
)

If the user has to be able to modify answer, we have to trick learnr, by recording "incorrect" answers. Here is another version allowing this, unfortunately with bright red buttons.

question_text(
  "Provide your answer",
  answer("C0rrect", correct = TRUE),
  incorrect = "Ok",
  try_again_button = "Modify your answer",
  allow_retry = TRUE
)

Topic One

question("Which planet do we live on?",
         answer("Mars", correct=FALSE),
         answer("Earth", correct = TRUE,  message = "Good job Earthling!"),
         answer("Saturn",  correct = FALSE),
         allow_retry = TRUE,
         random_answer_order = TRUE
        )

text

question_text(
  "Please enter the word 'C0rrect' below:",
  answer("correct", message = "Don't forget to capitalize"),
  answer("c0rrect", message = "Don't forget to capitalize"),
  answer("Crorrect", message = "Is it really an 'o'?"),
  answer("C0rrect ", message = "Make sure you do not have a trailing space"),
  answer("Correct", correct = TRUE),
  allow_retry = TRUE,
  trim = FALSE
)

grade_result()

grade_result() checks whether or not the student's code returns the correct result. It matches the result against one or more conditions and returns the message (and correct/incorrect status) associated with the first matched condition.

Here is an example of grade_result() in use.


grade_result(
  pass_if(str_length(.result) > 4, "Write some more")
)

Topic Two

text_check <- function(
  label,
  user_code,
  solution_code,
  check_code,
  envir_result,
  evaluate_result,
  envir_prep,
  ...
) {
  list(message = "Great job!", correct = TRUE, location = "append")
}


Video

If I make this into an embedded video (by prepending the link with "bang!") the event recorder doesn't always work.

Just a link

Finishing

question("Are you finished with the exercise?",
         answer("Yes", correct=TRUE),
         answer("No", correct=TRUE)
        )


dtkaplan/submitr documentation built on Sept. 20, 2020, 1:19 a.m.