【问题标题】:Randomization of question structure in r-examsr 考试中问题结构的随机化
【发布时间】:2021-09-03 08:27:58
【问题描述】:

我正在尝试创建一个画布测验,要求学生评估不同电路的有效电阻。该电路包含 2 到 4 个电阻,电阻值选自 E12 系列。为了回答这个问题,学生们展示了他们理解电阻器之间的并联和串联连接。

对于任何单个电路配置,我都可以提出问题(这里是两个串联电阻的示例)

    \begin{question}

What is the total resistance between points a and b if $R_1 = \Sexpr{r1}$ \Sexpr{char1_insert}$\Omega$ and $R_2 = \Sexpr{r2}$ \Sexpr{char2_insert}$\Omega$?
\setkeys{Gin}{width=0.3\textwidth}
<<fig=TRUE, height = 4, width = 4, echo=FALSE, eps=FALSE, results=hide>>=
plot.new()
rasterImage(im, 0, 0, 1, xmax)
@
 \end{question}

\begin{solution}
Resistors in series should be added. So 
\begin{eqnarray*}
R_{tot} & = & R_1 + R_2\\
R_{tot} & = & \Sexpr{r1_val} + \Sexpr{r2_val}\\
R_{tot} & = & \Sexpr{res}~\Omega
\end{eqnarray*}
\end{solution}

但我不知道如何随机选择问题类型。例如,如果脚本在两个串联电阻或三个串联电阻之间随机选择,则以下不起作用

    \begin{question}
What is the total resistance between points a and b given the following:
<<>>=
if (sel==1)
{
@
$R_1 = \Sexpr{r1}$ \Sexpr{char1_insert}$\Omega$, and $R_2 = \Sexpr{r2}$ \Sexpr{char2_insert}$\Omega$, arranged as shown in the schematic
<<>>=
} else if (sel == 2)
{
@
$R_1 = \Sexpr{r1}$ \Sexpr{char1_insert}$\Omega$, $R_2 = \Sexpr{r2}$ \Sexpr{char2_insert}$\Omega$, and $R_3 = \Sexpr{r3}$ \Sexpr{char3_insert}$\Omega$ arranged as shown in the schematic
<<fig=TRUE, height = 4, width = 4, echo=FALSE, eps=FALSE, results=hide>>=
plot.new()
rasterImage(im, 0, 0, 1, xmax)
@
\end{question}
#similar code for solution

我之所以会这样,是因为 if 语句被打断并且解释器对此感到窒息(我猜)。但是,有没有办法做到这一点?

【问题讨论】:

    标签: r r-exams


    【解决方案1】:

    是的,你说得对,这种方式的练习在语法上是不正确的,因此无法正确处理。

    您需要做的是将您的 R 变量(r1char1_insert1 等)插入 R 中的问题字符串(例如,使用 paste()sprintf()),然后插入整个字符串使用\Sexpr{} 进入{question}

    我在下面使用sprintf() 来说明这一点,其中%s 是要插入的字符串的占位符。这将替换原始版本中的 \Sexpr{} 插入。

    qu <- if(sel == 1) {
      sprintf("$R_1 = %s$ %s$\Omega$, and $R_2 = %s$ %s$\Omega$",
        r1, char1_insert, r2, char2_insert)
    } else {
      sprintf("$R_1 = %s$ %s$\Omega$, $R_2 = %s$ %s$\Omega$, and $R_3 = %s$ %s$\Omega$",
        r1, char1_insert, r2, char2_insert, r3, char3_insert)
    }
    

    这会产生一个包含问题文本的字符串qu。然后可以通过以下方式将其包含在{question} 中:

    What is the total resistance between points a and b if \Sexpr{qu},
    arranged as shown in the schematic
    

    【讨论】:

    • 啊,是的。我尝试了多个版本的尝试构造字符串,但没有尝试 sprintf()。我确实尝试过粘贴()。当结果回显到控制台时,格式似乎是正确的。但是,当我对文件调用exams2[格式选择] 时,结果字符串根本没有被处理。
    • 好的。那你现在解决问题了吗?如果是这样,请单击左侧的复选标记接受答案。如果仍有不清楚的地方,请继续提问。
    • 嗯,我可以发誓我在复选标记上打卡了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-02
    相关资源
    最近更新 更多