library(learnr)
library(parsons)
library(magrittr)

Parson's problems Hello World!

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"
)

Constructing a parsons's problem

To create a parsons problem in a learnr tutorial, use the question_parson() function.

You must provide at minimum:

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"
)

Using pass and fail conditions

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:

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"
)

Using multiple conditions

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"
)


rstudio/parsons documentation built on Nov. 5, 2019, 4:17 a.m.