title: "Adaptive Feedback for LearnR" author: "Daniel Kaplan" date: "February 2, 2018" output: ioslides_presentation: keep_md: yes logo: ~/KaplanFiles/Explore/checkr/inst/RStudioConf2018/mosaic-square.png self_contained: no smart: no widescreen: yes df_print: kable theme: yeti runtime: shiny_prerendered
Write the one-line version of "Hello, World!" in R. Your code should cause the message
Hello, World!
to appear.
Ordinarily, you would not show students the checkr
statements implementing this behavior. But our purpose here is to introduce checkr
, So here are the statements for the above exercise.
[1] code <- for_checkr(USER_CODE)
[2] res <- misconception(code, line_where(code, passif(is.null(F))),
[3] message = paste("Just typing the string doesn't do it. Note that the output",
[4] "has quotes and is formatted as an output, not a simple message."))
[5] res <- misconception(res, line_where(res, passif(F == print)),
[6] message = paste("Using print() isn't right.", "True, that's the way character strings are displayed,",
[7] "but the format of the display is as a quoted output and",
[8] "not just a simple message."))
[9] res <- line_where(res, insist(F == cat, "Try the cat() function."))
[10] check(arg_number(res, 1), passif(V == "Hello, World!", "Good job!"),
[11] failif(tolower(V) == "hello, world!", "Get the capitalization right!"),
[12] failif(TRUE, "The string should be 'Hello, World!', not '{{V}}'."))
Breaking this down, line by line:
learnr
. This is always called USER_CODE
. The function for_check()
does some pre-processing of the user submission to turn it into evaluated code and format it for use in later checkr
functions.misconception()
function will generate a checkr
fail message, if the pattern identified in the second argument passes. That pattern, line_where(code, is.null(F))
, means, "scan the code looking for a line where no function is being used." This will captures a line that contains only a character string.print()
on the string. cat()
. If not, the check fails. (Note that [5] already ruled out that print()
was being invoked.)cat()
function. (We know it's cat()
, because [9] has established this.) If that argument is exactly `"Hello, World!" the submission passes. Otherwise, we check for a particular error involving capitalization and, if that's not the case, generate a message to tell the student what's wrong.Depending on the submission, any of the checks on lines 2, 5, 9, and 10 might fail. If a check fails, later checks that use the previous result will short circuit to a failed check. For instance, if the check on line [2] fails, the remaining checks won't be performed in detail: they will just pass along the failed result from line [2].
An instructor with a different pedagogical approach might prefer to structure the checking in an entirely different way. For instance, here are checkr
statements that simply tell the user whether or not the submission did what was requested:
## [1] code <- for_checkr(USER_CODE)
## [2] line_binding(code, cat("Hello, World!"), passif(TRUE, "That's right."),
## [3] fail = "No. Try aain.")
This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.