Created
December 3, 2019 00:37
-
-
Save kenjisato/1a81c13db2234ffe52df51991aa64843 to your computer and use it in GitHub Desktop.
Parameterized xweave, an idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```{r eval=is.null(params), echo=FALSE} | |
n <- 5 | |
``` | |
```{r, include=FALSE} | |
alternatives <- tibble::tribble( | |
~answer, ~correct, ~solution, | |
# 1 | |
"Zurich is the capital of Switzerland.", FALSE, | |
"False. There is no de jure capital but the de facto capital of Switzerland is Bern.", | |
# 2 | |
"Italian is an official language in Switzerland.", TRUE, | |
"True. The official languages are: German, French, Italian, Romansh.", | |
# 3 | |
"The currency in Switzerland is the Euro.", FALSE, | |
"False. The currency is the Swiss Franc (CHF).", | |
# 4 | |
"Switzerland is part of the European Union (EU).", FALSE, | |
"False. Switzerland is part of the Schengen Area but not the EU.", | |
# 5 | |
"The Swiss national holiday is August 1.", TRUE, | |
"True. The establishment of the Swiss Confederation is traditionally dated to August 1, 1291." | |
) | |
choice <- sample(seq_len(nrow(alternatives)), n) | |
``` | |
Question | |
======== | |
Which of the following statements about Switzerland is correct? | |
```{r, results='asis', echo=FALSE} | |
answerlist(alternatives$answer[choice], markup = 'markdown') | |
``` | |
Solution | |
======== | |
```{r, results='asis', echo=FALSE} | |
answerlist(alternatives$solution[choice], markup = 'markdown') | |
``` | |
Meta-information | |
================ | |
exname: About Switzerland | |
extype: mchoice | |
exsolution: `r mchoice2string(alternatives$correct[choice])` | |
exshuffle: TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pass parameters as a list | |
weave <- function(file, params = NULL) { | |
envir <- if (!is.null(params)) list2env(params) else new.env() | |
knitr::knit(file, envir=envir) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment