library(learnr) library(parsons) library(magrittr)
A Parsons problem gives the student some programming statements in random order. The student then constructs an answer by dragging the statements into the correct order.
Here is an example. Drag the statements from the top panel to the bottom panel to produce "Hello World!".
question_parsons( initial = c( "Hello", "World", "!" ), pass_if( c( "Hello", "World", "!" ) ), problem_type = "base" )
To create a parsons problem in a learnr
tutorial, use the question_parson()
function.
You must provide at minimum:
The initial
set of values, as a character vector
A "correct" answer
Note that, when using only this minimal specification, the only feedback the student will ever get is "Incorrect, try again".
question_parsons( initial = c( "Hello", "World", "!" ), answer( c( "Hello", "World", "!" ), correct = TRUE ), problem_type = "base" )
An alternative way to specify the correct answer(s) is to supply a pass_if()
statement. Using pass_if()
and fail_if()
is a powerful way to provide feedback to your students.
These pass_if()
and fail_if()
statements are evaluated in turn, until the first expectation evaluates to TRUE
, and the leanr
will provide the feedback in the message
.
You can specify pass_if()
as well as fail_if()
in any of the following ways:
A character vector, that must be matched exactly, or
A function in the tradition form function(x) ...
, e.g. function(x) length(x) < 3
A function specified using the rlang
tidy evaluation formula notation, e.g. ~length(.) < 3
This next example will give feedback if the length of the answer is 2 or fewer items.
question_parsons( initial = c( "Hello", "World", "!" ), pass_if( c( "Hello", "World", "!" ) ), fail_if( ~length(.) <= 2, "Provide more answers" ), problem_type = "base" )
Create a statement that uses iris
data, then does some mutation and finally creates a summary.
question_parsons( initial = c( "iris", "mutate(...)", "summarize(...)", "print()" ), pass_if( c( "iris", "mutate(...)", "summarize(...)" ) ), fail_if( ~length(.) < 2, message = "Include at least two answers" ), fail_if( function(x){"print()" %in% x}, message = "You should not include print() in your answer" ), fail_if( ~{.[1] != "iris"}, message = "Your solution should start with 'iris'" ), fail_if( ~length(.) < 3, message = "Use at least 3 elements to form your answer" ), problem_type = "tidyverse" )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.