r - lintr 测试通过 devtools::check() 并通过 devtools::test() 失败
问题描述
我正在编写一个带有以下 lint 测试的 R 包:
context("Require no code style errors")
library(lintr)
test_that("Package has no lintr errors", {
lintr::expect_lint_free()
})
测试通过 `devtools::check():
$ Rscript -e "devtools::check()"
...
─ checking tests ...
✔ Running ‘testthat.R’ [61s/65s]
...
0 errors ✔ | 0 warnings ✔ | 0 notes ✔
并且无绒测试失败devtools::test()
:
$ Rscript -e "devtools::test()"
...
Testing PosteriorBootstrap
...
✖ | 0 1 | Require no code style errors [6.2 s]
────────────────────────────────────────────────────────────────────────────────
test_lintr.R:5: failure: Package has no lintr errors
Not lint free
tests/testthat/test_anpl.R:112:1: style: Trailing whitespace is superfluous.
^~
...
OK: 20
Failed: 1
Warnings: 0
Skipped: 0
问题是 Github 和 Travis 被设置为拒绝测试失败的拉取请求,如果我在devtools::test()
之后运行devtools::check()
,所有其他测试都会运行两次。
我怎样才能devtools::check()
运行lintr
测试?
解决方案
这个问题是一个已知问题:
这不是 devtools 中的错误(但可能在 lintr 中)。
devtools::check()
在临时目录中运行检查,但lint_package()
假定它正在包目录中运行,因此没有要检查的源文件。...您可以使用 来确认这一点devtools::check(check_dir = ".")
,如果确实如此,这应该会产生 linting 失败devtools::test()
。
2015 年 5 月提出的解决方案不再有效。该问题现已锁定并关闭,因此不太可能得到解决。
我建议运行检查并将测试范围缩小到lintr
:
Rscript -e "devtools::check();devtools::test_file(file = 'testthat/test_lintr.R')"
推荐阅读
- python - 如何在数据集中添加异常
- visual-studio-code - 如何在 VS Code 侧边栏中预览打开的端口?
- docker - 连接 dockerized 应用程序网络以进行 api 调用
- json - 如何抓取包含在 HTML 页面中的 JSON 标记
- javascript - How to update the table when same record is inserted using jquery
- list - 返回列表中的特定元素 - LISP
- swift - 如何在@propertyWrapper 中获取父母的自我?
- android - Installation did not succeed. The application could not be installed. Installation failed due to:
- python - 熊猫的虚拟函数(sklearn.pipeline)
- google-bigquery - 如何安排查询并将结果保存在不同的项目中?