R/exams 似乎没有返回考试的正确答案

R/exams appears not returning the right solution of an exam

我有以下问题:

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, include = FALSE}
correct <- c(
  "A (correct)
  \vspace{1cm}
  
  $$\int f\left(x\right) dx$$
  
  ", 
  "B (correct)",
  "C (correct)"
)
correct <- sample(correct, 2)

incorrect <- c(
  "D (incorrect)",
  "E (incorrect)",
  "F (incorrect)",
  "G (incorrect)",
  "H (incorrect)",
  "I (incorrect)"
)
incorrect <- sample(incorrect, 6)
```

Question
========
  
Select from the followings items.

\begin{answerlist}
  \item `r correct[1]`
  \item `r correct[2]`
  \item `r incorrect[1]`
  \item `r incorrect[2]`
  \item `r incorrect[3]`
  \item `r incorrect[4]`
  \item `r incorrect[5]`
  \item `r incorrect[6]`
\end{answerlist}

Meta-information
================
exname: My question
extype: mchoice
exsolution: 11000000
exshuffle: TRUE

我使用以下代码生成考试:

library(exams)

myexam <- list(
  "question.Rmd",
  "question.Rmd",
  "question.Rmd",
  "question.Rmd"
)

exm <- exams2pdf(myexam,dir = "/tmp/", template = "x.tex")

exm[[1]][[1]]$metainfo$solution

我的模板在哪里:

\documentclass[a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[portuges]{babel}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{longtable}
\usepackage{multicol}
\usepackage{enumitem}
\setlength{\parindent}{0em}
\setlength{\parskip}{\bigskipamount}
\pagestyle{fancy}
\setlength\headheight{55pt}
\fancyhf{} % sets both header and footer to nothing
\renewcommand{\headrulewidth}{0pt}

\newenvironment{answerlist}%
  {\renewcommand{\labelenumii}{(\alph{enumii})}\begin{multicols}{4}\begin{enumerate}}%
  {\end{enumerate}\end{multicols}}

\newenvironment{question}{\item }{}

%\setkeys{Gin}{keepaspectratio}



\begin{document}

This is my exam!

Part 1

\begin{enumerate}
%% \exinput{exercises}
\end{enumerate}

Part 2

\begin{enumerate}[resume]
\input{exercise4}
\end{enumerate}

\end{document}

然而,我在考试中的问题 1 的解决方案不正确 (exm[[1]][[1]]$metainfo$solution)。这是一个错误吗?还是我做错了什么?

然而,我在考试中的问题 1 的解决方案不正确 (exm[[1]][[1]]$metainfo$solution)。这是一个错误吗?还是我做错了什么?

(很抱歉重复最后一段,否则 Whosebug 不允许我 post——它抱怨代码太多。)

问题是您在 Markdown 练习中使用了 LaTeX 风格的 {answerlist} 环境。因此,答案列表在内部没有被正确处理,但它仍然被渲染,但只有在通过 LaTeX 这样做时(就像你在 exams2pdf() 中所做的那样)。如果您使用 exams2html("question.Rmd"),您会看到未显示答案列表。不幸的是,没有抛出错误,我会检查是否可以改进。

要解决此问题,您需要使用 Markdown 样式的问题列表,或者“手动”

Answerlist
----------
* `r correct[1]`
* `r correct[2]`
* `r incorrect[1]`
* `r incorrect[2]`
* `r incorrect[3]`
* `r incorrect[4]`
* `r incorrect[5]`
* `r incorrect[6]`

或通过 answerlist() 函数(已在 中显示)。

```{r, echo = FALSE, results = "asis"}
answerlist(c(correct, incorrect), markup = "markdown")
```