Skip to content

Instantly share code, notes, and snippets.

@kenjisato
Created December 3, 2019 00:37
Show Gist options
  • Save kenjisato/1a81c13db2234ffe52df51991aa64843 to your computer and use it in GitHub Desktop.
Save kenjisato/1a81c13db2234ffe52df51991aa64843 to your computer and use it in GitHub Desktop.
Parameterized xweave, an idea
```{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
# 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