6

This test in my package works fine with devtools::test(). Also the online Travis build is going well.

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

However, with devtools::check() it fails. The error message is

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

I'm running R version 3.6.3 (2020-02-29), testthat 2.3.2 and lintr 2.0.1 on Windows.

I think the problem is that lintr doesn't know which file(s) to lintr.

Could somebody please point out to me what the solution to this problem is?

Willy
  • 497
  • 3
  • 10

1 Answers1

0

This is known bug with lintr. Currently, the best workaround for it is replacing your code with:

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()
      )
    }
  })
}

The source for this solution is in that same link.

faken
  • 6,572
  • 4
  • 27
  • 28