problems using data.table in question template R-exams

Viewed 162

I am stuck with this question that wants to use data.table. I used dplyr successfully in other questions, so i am a bit puzzled whats going on.

```{r data generation, echo = FALSE, results = "hide", cache=FALSE}


library(data.table)
library(ggplot2)

# data.table hack?
d <- income <- id <- it <- age <- .N <- NULL

n = 100
IT = 40
pension = 1.0
inc1 = runif(n = 1, min = 0.06, max = 0.08)
inc2 = -0.0008
alphas = runif(n,min = 0, max = 1)
epsilon = 0.2

d = data.table(expand.grid(id=1:n, it = 1:IT))
d[ , alpha := alphas[id]]
d[ , age := it + 19]
d[ , shock := rnorm(n = .N, sd = epsilon)]
d[ , income := exp(alpha + inc1 * age + inc2* age^2 + shock)]
d[, alpha := NULL]
d[, shock := NULL]
# end data generation
fwrite(d, file = "panel.csv")

questions <- solutions <- expl <- list()
type <- list()

# how many individuals do you observe?
questions[[1]] <- "how many individuals do you observe?"
solutions[[1]] <- d[ , max(id)]
type[[1]] <- "num"
expl[[1]] <- "look at the biggest id entry"
# 
# 
# # how many time periods?
questions[[2]] <- "how many time periods?"
solutions[[2]] <- d[ , max(it)]
expl[[2]] <- "look at the biggest it entry"
type[[2]] <- "num"
```


Question
========

In this question you should use the data set saved at [this link](panel.csv) for you. Please download from moodle by right-clicking and saving on your computer. I use the dataset as object `d` in my solutions.

```{r questionlist, echo = FALSE, results = "asis"}
answerlist(unlist(questions), markup = "markdown")
```


Solution
========

```{r solutionlist, echo = FALSE, results = "asis"}
answerlist(unlist(solutions),paste(unlist(expl), ".", sep = ""), markup = "markdown")
```



Meta-information
================
extype: cloze
exsolution: `r paste(solutions, collapse = "|")`
exclozetype: `r paste(type, collapse = "|")`
exname: panel
extol: 0.05

If i run this i get

> exams2html("exercises/panel/paneltest.Rmd")
Error in read_metainfo(file) : no exsolution specified

while executing the Rmd in the global scope returns the correct answer:

> answerlist(unlist(questions), markup = "markdown")
Answerlist
----------
* how many individuals do you observe?
* how many time periods?
> answerlist(unlist(solutions),paste(unlist(expl), ".", sep = ""), markup = "markdown")
Answerlist
----------
* 100. look at the biggest id entry.
* 40. look at the biggest it entry.

Thanks for any hints!

0 Answers
Related