假设我正在开发一个 R 包,并且有一些用
R CMD check
执行的测试。
我希望其中一些测试只在我在我的机器上本地构建包时执行,而当包由 CRAN 处理时被跳过。
一个解决方案是在将包上传到 CRAN 之前注释掉那些测试,但这是容易出错的和手动的。
我可以添加一些 if 语句或设置以实现此目的吗?
skip_on_cran()
是你需要的。
test_that("skip example", {
expect_equal(1, 1L) # this expectation runs
skip_on_cran()
expect_equal(1, 2) # this one skipped
expect_equal(1, 3) # this one is also skipped
})