Chapter 3 Webex

Use the following code to install webex from CRAN:

install.packages("webex")

If you're using bookdown 0.22, you need to use webex version 0.9.2 or above to avoid an error when you use the hide() function.

The webex package is called in the setup chunk, so you don't need to call it on every page you want to use webex.

If you're using webex outside of this bookdown template, such as in an rmarkdown webpage, you will need to set the output type to webex::webex_default in the yaml header in order to import the css and javascript files. To create a file from the webex template in RStudio, click File -> New File... -> RMarkdown and in the dialog box that appears, select From Template and choose Web Exercises.

3.1 Fill-In-The-Blanks (fitb())

Create fill-in-the-blank questions using fitb(), providing the answer as the first argument (e.g., fitb("4")).

  • 2 + 2 is

You can also create these questions dynamically, using variables from your R session (e.g., x <- sample(2:8, 1); fitb(x)).

  • The square root of 25 is:

The blanks are case-sensitive; if you don't care about case, use the argument ignore_case = TRUE (e.g., fitb("E", ignore_case = TRUE)).

  • What is the letter after D?

If you want to ignore differences in whitespace use, use the argument ignore_ws = TRUE and include spaces in your answer anywhere they could be acceptable (e.g., fitb("library( tidyverse )")).

  • How do you load the tidyverse package?

You can set more than one possible correct answer by setting the answers as a vector (e.g., fitb(c("A", "E", "I", "O" , "U"), ignore_case = TRUE)).

  • Type a vowel:

You can use regular expressions to test answers against more complex rules (e.g., fitb("^[a-zA-Z]{3}$", width = 3, regex = TRUE)),.

  • Type any 3 letters:

3.2 Multiple Choice (mcq())

Make a multiple choice question by setting the first argument to mcq() to a vector where the answer(s) are labeled answer (e.g., mcq(c("0", "3.14", answer = "42", "100", "none of the above")))

  • "Never gonna give you up, never gonna: "
  • "I down in Africa"
  • "There's nothing that a hundred men could ever do"

3.3 True or False (torf())

You can make a quick true-of-false option using torf() (e.g., torf(FALSE)).

  • You can permute values in a vector using sample().

3.4 Hidden solutions and hints (hide() and unhide())

You can fence off a solution area that will be hidden behind a button using hide() before the solution and unhide() after, each as inline R code. Pass the text you want to appear on the button to the hide() function.

If the solution is an RMarkdown code chunk, instead of using hide() and unhide(), simply set the webex.hide chunk option to TRUE, or set it to the string you wish to display on the button.

  • Recreate the scatterplot below, using the built-in cars dataset.
Recreate this scatterplot.

Figure 3.1: Recreate this scatterplot.

?plot

plot(cars$speed, cars$dist)
TRUE

Figure 3.2: TRUE