在 exams2moodle 的文件名中使用 paste0
using paste0 in file name in exams2moodle
我正在尝试使用 exams
包创建一个循环来自动生成考试....
我创建了一系列这样的练习
gr1 <- c("ae1_IntroEst_1.Rmd","ae1_IntroEst_2.Rmd","ae1_IntroEst_3.Rmd","ae1_IntroEst_4.Rmd")
gr2 <- c("ae1_IntroProcEst_1.Rmd","ae1_IntroProcEst_2.Rmd","ae1_IntroProcEst_3.Rmd","ae1_IntroProcEst_4.Rmd")
...etc...
现在,我正在创建一个循环以将所有练习导出到 moodle xml:
for (i in 1:2){
grupo <- paste0("gr",i)
exams2moodle(grupo, name = paste0("mt1_",i, "_M"), dir = "nops_moodle", encoding = "UTF-8", schoice = list(answernumbering = "none", eval = ee))
}
但是我收到这个错误:
Error in xexams(file, n = n, nsamp = nsamp, driver = list(sweave = list(quiet = quiet, : The following files cannot be found: gr11.
如果我将“grupo”替换为“gr1”,那么它就可以工作...(但我生成了 20 个练习)。我想不通...
有什么想法吗?
谢谢!
因为grupo
是一个字符串:"gr1"
。 exams2moodle
的第一个参数是一个字符串(在您的情况下)而不是文件列表(如您所愿)。
如果你想使用名称在字符串变量中的变量,你应该使用get (get: Return 命名对象的值)
查看示例代码:
> x <- 'foo'
> foo <- 'bar'
> x
[1] "foo"
> get(x)
[1] "bar"
>
你的情况:
for (i in 1:2){
grupo <- paste0("gr",i)
exams2moodle(get(grupo), name = paste0("mt1_",i, "_M"), dir = "nops_moodle", encoding = "UTF-8", schoice = list(answernumbering = "none", eval = ee))
}
我正在尝试使用 exams
包创建一个循环来自动生成考试....
我创建了一系列这样的练习
gr1 <- c("ae1_IntroEst_1.Rmd","ae1_IntroEst_2.Rmd","ae1_IntroEst_3.Rmd","ae1_IntroEst_4.Rmd")
gr2 <- c("ae1_IntroProcEst_1.Rmd","ae1_IntroProcEst_2.Rmd","ae1_IntroProcEst_3.Rmd","ae1_IntroProcEst_4.Rmd")
...etc...
现在,我正在创建一个循环以将所有练习导出到 moodle xml:
for (i in 1:2){
grupo <- paste0("gr",i)
exams2moodle(grupo, name = paste0("mt1_",i, "_M"), dir = "nops_moodle", encoding = "UTF-8", schoice = list(answernumbering = "none", eval = ee))
}
但是我收到这个错误:
Error in xexams(file, n = n, nsamp = nsamp, driver = list(sweave = list(quiet = quiet, : The following files cannot be found: gr11.
如果我将“grupo”替换为“gr1”,那么它就可以工作...(但我生成了 20 个练习)。我想不通...
有什么想法吗?
谢谢!
因为grupo
是一个字符串:"gr1"
。 exams2moodle
的第一个参数是一个字符串(在您的情况下)而不是文件列表(如您所愿)。
如果你想使用名称在字符串变量中的变量,你应该使用get (get: Return 命名对象的值)
查看示例代码:
> x <- 'foo'
> foo <- 'bar'
> x
[1] "foo"
> get(x)
[1] "bar"
>
你的情况:
for (i in 1:2){
grupo <- paste0("gr",i)
exams2moodle(get(grupo), name = paste0("mt1_",i, "_M"), dir = "nops_moodle", encoding = "UTF-8", schoice = list(answernumbering = "none", eval = ee))
}