0

I am writing an R package with the following lint test:

context("Require no code style errors")
library(lintr)

test_that("Package has no lintr errors", {
    lintr::expect_lint_free()
})

The tests pass with `devtools::check():

$ Rscript -e "devtools::check()"
...
─  checking tests ...
✔  Running ‘testthat.R’ [61s/65s]
...
0 errors ✔ | 0 warnings ✔ | 0 notes ✔

and the lint-free test fails with 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

The problem is that Github and Travis are set to reject pull requests that fail the tests, and that if I run devtools::test() after devtools::check(), all the other tests run twice.

How can I get devtools::check() to run the lintr test?

miguelmorin
  • 5,025
  • 4
  • 29
  • 64

1 Answers1

0

This problem is a known issue:

This is not a bug in devtools (but maybe in lintr). devtools::check() runs the check in a temporary directory, but lint_package() assumes it is being run in a package directory, therefore there are no source files to be linted. ... you can confirm this with devtools::check(check_dir = "."), which should produce linting failures if devtools::test() does.

The solution proposed, written in May 2015, no longer works. The issue is now locked and closed, so it's unlikely to be addressed.

I suggest running the check and narrowing the test only to lintr:

Rscript -e "devtools::check();devtools::test_file(file = 'testthat/test_lintr.R')"
miguelmorin
  • 5,025
  • 4
  • 29
  • 64