上个月收到 CRAN 来信,让修改 beginr 这个包,以适应未来 R 版本的变化。我不知是忙是懒还是蠢,总之是错过了死线。刚过六一,发现 beginr 被从 CRAN 移除了。
移除就移除吧。R 包的后期维护太累了,哪怕是个弱包。但麻烦的是, beginr 被我不知好歹地写进《学 R》书里了,昨天有读者反馈,说这包按书里写的装不上呀。
骑虎难下。所以就来求助了。
CRAN 的来信如下:
(The packages) fail when checking with env var R_CHECK_LENGTH_1_CONDITION set to true, which turns using if() with conditions of length greater than one from a warning into an error.
We really would like to have (the current development version of) R move from giving a warning to giving an error by default in the near future, but would prefer not breaking too many CRAN (and BioC) packages.
We understand that you have already been contacted at least twice by Tomas Kalibera to fix your packages to no longer use if() with conditions of length greater than one: we really need new versions of your packages fixing this as soon as possible.
我理解的是,if()
函数的参数要求长度为 1。如果超过 1,R 目前会返回 warning。将来会改成返回 error。
例如:
x <- 1:3
if(x > 2) help()
当前版本 (R 3.5) 返回警告:
Warning message:
In if (x > 2) help() :
the condition has length > 1 and only the first element will be used
beginr 包里好多处用到了 if()
,那么我的问题是,该怎么改才能满足 CRAN 的要求?是不是外面加上一层长度判断就行了,比如上面的例子改为:
x <- 1:3
if(length(x) == 1) {
if(x > 2) help()
}
我怎么觉得这样有点多此一举呢……不知列位有何高见?