5

我的包中的这个测试适用于devtools::test(). 在线 Travis 构建也进展顺利。

test_that("Package style", {
  lintr::expect_lint_free()
})

但是,devtools::check()它失败了。错误信息是

   invalid 'path' argument
     Backtrace:
      1. lintr::expect_lint_free()
      2. lintr::lint_package(...)
      3. base::normalizePath(path, mustWork = FALSE)
      4. base::path.expand(path)

我在 Windows 上运行 R 版本 3.6.3 (2020-02-29),testthat 2.3.2 和 lintr 2.0.1。

我认为问题在于 lintr 不知道要 lintr 哪个文件。

有人可以向我指出这个问题的解决方案是什么吗?

4

1 回答 1

0

这是lintr的已知错误。目前,最好的解决方法是将您的代码替换为:

if (requireNamespace("lintr", quietly = TRUE)) {
  library(lintr)

  context("linting package")
  test_that("Package Style", {

    # A duplicate copy of the find_package function from lintr
    find_package <- function(path) {
      path <- normalizePath(path, mustWork = FALSE)

      while (!file.exists(file.path(path, "DESCRIPTION"))) {
        path <- dirname(path)
        if (identical(path, dirname(path))) {
          return(NULL)
        }
      }

      path
    }

    if (!is.null(find_package("."))) {
      expect_lint_free()
      )
    }
  })
}

此解决方案的来源在同一个链接中。

于 2022-02-02T22:27:11.287 回答