在向量上使用 assert_that 会引发错误
using assert_that on vectors throws error
我正在尝试检查向量中的每个值是否小于或等于 2。assert_that 似乎对此有疑问(可能是由于我缺乏理解)。有人可以告诉我这里有什么问题吗?
> require(assertthat)
> x<-c(1,2,1.5)
> assert_that(x<=2) #should return true
Error: assert_that: assertion has length greater than 1
> y<-c(1,2,1.5,3,3)
> assert_that(y<=2) #should return false
Error: assert_that: assertion has length greater than 1
> stopifnot(x<=2)
随便说说
assert_that(y<=2)
是模棱两可的。你要全部y<=2
吗?你想要至少一个y<=2
吗?您可以分别使用 assert_that(all(y<=2))
或 assert_that(any(y<=2))
来折叠成一个断言。
我正在尝试检查向量中的每个值是否小于或等于 2。assert_that 似乎对此有疑问(可能是由于我缺乏理解)。有人可以告诉我这里有什么问题吗?
> require(assertthat)
> x<-c(1,2,1.5)
> assert_that(x<=2) #should return true
Error: assert_that: assertion has length greater than 1
> y<-c(1,2,1.5,3,3)
> assert_that(y<=2) #should return false
Error: assert_that: assertion has length greater than 1
> stopifnot(x<=2)
随便说说
assert_that(y<=2)
是模棱两可的。你要全部y<=2
吗?你想要至少一个y<=2
吗?您可以分别使用 assert_that(all(y<=2))
或 assert_that(any(y<=2))
来折叠成一个断言。