【发布时间】:2021-01-04 05:38:59
【问题描述】:
我创建了如下函数:
#!/usr/bin/Rscript
targetRunner <- function(temp) {
cost <- ((temp - 32) * (5 / 9)) + 273.15
return(cost)
}
args <- commandArgs(trailingOnly=TRUE)
if (length(args) > 0) {
targetRunner(as.numeric(args[1]))
} else {
print("Supply one argument as the numeric value: usage ./target-runner temp")
}
我可以从 Linux 终端完美地运行这个功能。但是,当我将它作为 tragetRunner 引入 iRace 包并使用checkIraceScenario(scenario = scenario) 检查我是否已为该包准备好一切时,我收到以下错误:
...
== irace == The output was:
[1] NA
...
# targetRunner returned:
NULL
根据 iRace 包的用户指南,仅当此函数的结果不是数值时才会出现此错误。请告诉我为什么这个函数不返回数值?
【问题讨论】:
-
此函数不能不返回数值。但是,它可以返回长度为 0 的数字向量(如果
as.numeric(args[1])是NULL),它可以返回数字NA或NaN值(如果as.numeric(args[1])是NA或NaN)。在您的情况下,它似乎返回NA。