Here’s a simple exercise with an empty code chunk provided for entering the answer.
Write the R code required to add two plus two:
Here’s an exercise with some prepopulated code as well as exercise.lines = 5
to provide a bit more initial room to work.
Now write a function that adds any two numbers and then call it:
Here’s an exercise where the chunk is pre-evaluated via the exercise.eval
option (so the user can see the default output we’d like them to customize). We also add a “hint” to the correct solution via the chunk immediate below labeled print-limit-hint
.
Modify the following code to limit the number of rows printed to 5:
## mpg cyl disp hp drat wt qsec vs am gear carb
## Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
## Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
## Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
## Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
## [ reached 'max' / getOption("max.print") -- omitted 28 rows ]
## mpg cyl disp hp drat wt qsec vs am gear carb
## Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
## Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
## Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
## Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
## [ reached 'max' / getOption("max.print") -- omitted 2 rows ]
You can include any number of single or multiple choice questions as a quiz. Use the question
function to define a question and the quiz
function for grouping multiple questions together.
Some questions to verify that you understand the purposes of various base and recommended R packages: