当我加载 dplyr 库时,我注意到 R 考试包中的奇怪行为。下面的示例仅在我明确调用 dplyr 命名空间时才有效,如注释中所示。请注意,该错误仅发生在新会话中,即您需要重新启动 R 才能看到我看到的内容。您需要将以下内容放在文件exam.Rmd
中,然后调用
library(exams)
library(dplyr)
exams2html("exam.Rmd") # in pwd
# this is exam.Rmd
```{r datagen,echo=FALSE,results='hide',warning=FALSE,message=FALSE}
df = data.frame(i = 1:4, y = 1:4, group = paste0("g",rep(1:2,2)))
# works:
b2 = diff(dplyr::filter(df,group!="g1")$y)
b3 = diff(dplyr::filter(df,group!="g2")$y)
# messes up the complete exercise:
# b2 = diff(filter(df,group!="g1")$y)
# b3 = diff(filter(df,group!="g2")$y)
nq = 2
questions <- solutions <- explanations <- rep(list(""), nq)
type <- rep(list("num"),nq)
questions[[1]] = "What is the value of $b_2$ rounded to 3 digits?"
questions[[2]] = "What is the value of $b_3$ rounded to 3 digits?"
solutions[[1]] = b2
solutions[[2]] = b3
explanations[[1]] = paste("You have you substract the conditional mean of group 2 from the reference group 1. gives:",b2)
explanations[[2]] = paste("You have you substract the conditional mean of group 3 from the reference group 1",b3)
```
Question
========
You are given the following dataset on two variables `y` and `group`.
```{r showdata,echo=FALSE}
# kable(df,row.names = FALSE,align = "c")
df
```
some text with math
$y_i = b_0 + b_2 g_{2,i} + b_3 g_{3,i} + e_i$
```{r questionlist, echo = FALSE, results = "asis"}
answerlist(unlist(questions), markup = "markdown")
```
Solution
========
```{r sollist, echo = FALSE, results = "asis"}
answerlist(unlist(explanations), markup = "markdown")
```
Meta-information
================
extype: cloze
exsolution: `r paste(solutions,collapse = "|")`
exclozetype: `r paste(type, collapse = "|")`
exname: Dummy Manual computation
extol: 0.001