This is a Web Exercise template created by the psychology teaching team at the University of Glasgow, based on ideas from Software Carpentry. This template shows how instructors can easily create interactive web documents that students can use in self-guided learning.
The {webexercises}
package provides a number of
functions that you use in inline
R codeor through code chunk options to create HTML widgets (text
boxes, pull down menus, buttons that reveal hidden content). Examples
are given below. Knit this file to HTML to see how it works.
NOTE: To use the widgets in the compiled HTML file, you need to have a JavaScript-enabled browser.
total_correct()
)The function total_correct()
displays a running total of
correct responses. Change the elem
argument to display in a
different style (e.g., h2
or h3
for header
styles). If you're comfortable with css styles or classes, you can add
them with the args
argument.
fitb()
)Create fill-in-the-blank questions using fitb()
,
providing the answer as the first argument.
You can also create these questions dynamically, using variables from your R session.
The blanks are case-sensitive; if you don't care about case, use the
argument ignore_case = TRUE
.
If you want to ignore differences in whitespace use, use the argument
ignore_ws = TRUE
(which is the default) and include spaces
in your answer anywhere they could be acceptable.
You can set more than one possible correct answer by setting the answers as a vector.
You can use regular expressions to test answers against more complex rules.
mcq()
)torf()
)sample()
.
longmcq()
)When your answers are very long, sometimes a drop-down select box
gets formatted oddly. You can use longmcq()
to deal with
this. Since the answers are long, It's probably best to set up the
options inside an R chunk with echo=FALSE
.
What is a p-value?
What is true about a 95% confidence interval of the mean?