You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R/exams数值型习题答案过大触发报错的技术咨询

问题分析与解决

这不是软件bug,是操作疏漏导致的。

原因

R默认会对较大数值自动采用科学计数法(比如1e4),而R/exams的string2num()函数要求exsolution必须是常规十进制格式的字符串,无法识别科学计数法格式的内容,因此触发报错。

解决方法

修改习题文件中的代码,将数值转换为常规十进制格式,避免科学计数法输出:

修改后的习题文件(test-debug.Rmd)

Question
========
Some text

Solution
========
Some solution

```{r}
# 强制禁用科学计数法,确保输出为常规数字
options(scipen = 999)
sol <- 1e4
# 转换为字符串格式
sol_str <- as.character(sol)
Meta-information

exname: test-debug
extype: num
exsolution: r sol_str

也可以直接用`format()`函数精准控制输出格式:
```r
sol <- 1e4
sol_str <- format(sol, scientific = FALSE)

渲染代码保持不变

exams2html(file = "test-debug.Rmd",
           edir = path_to_exercise,
           dir = path_output)

补充说明

如果需要保留指定小数位数,可在format()中添加digits参数,比如format(sol, scientific = FALSE, digits = 2)来控制数值精度。

内容的提问来源于stack exchange,提问作者Sebastian Sauer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 22:11:02