Problem
I am integrating lintr testing into an R package but I want to exclude the zzz.R file contained in the R directory for various reasons. When using lintr::expect_lint_free(exclusions = list("R/zzz.R"))
it does not seem to properly exclude the exclusion, but if I use lintr::lint_package(exclusions = list("R/zzz.R"))
it properly excludes the zzz.R file. See below.
Example
Below is a simple example illustrating differing results. You can also use this example pkg to reproduce this sample problem.
Question
Maybe I'm missing something but I thought expect_lint_free
passed its arguments to lint_package
? Is there different procedure for specifying files to exclude from linting when using lintr::expect_lint_free()
? If this is a bug then I'll post an issue on Github but I wanted to make sure I wasn't overlooking some.
1 Like
cderv
November 8, 2019, 12:24am
2
With testthat tests are running in a working directory corresponding to where the testtfiles are. i.e tests/testthat
If I try
lintr::expect_lint_free(exclusions = list("../../R/zzz.R"))
this works.
And with this too
lintr::expect_lint_free(
exclusions = list(
rprojroot::find_package_root_file("R/zzz.R")
))
I think there is a bug here or at least something to be improved because it does not seems right to take care of that.
One thing that make me think of a bug is the fact defining exclusions
in option file does not work either
# .lintr file
exclusions: "R/zzz.R"
see ?read_setting
about this option
You need to exclude in absolute path, but lintr
should handle relative path I guess
3 Likes
cderv
November 8, 2019, 8:22pm
3
There is an issue that seems related but it is said to be fixed
opened 01:23AM - 20 Mar 18 UTC
closed 04:48PM - 20 Mar 18 UTC
Hello Jim,
I've been running into an issue trying to lint a package while pas… sing file exclusions via the `...`. From my understanding, the `...` should be passed from `lint_package()` -> `lint()` -> `exclude()`, which is where I want my exclusions `list()` to end up. It's a little difficult to provide a `reprex` but here is an example.
```{r}
library(lintr)
lint_package(".", exclusions = list("inst/examples/bad_lint.R"))
```
The problem is that the list of excluded files are **not** being ignored. I have traced the issue to `lintr:::exclude()`, and it stems from the fact that the filenames in the `df` object (e.g. df$filename[1]) are written as full *absolute paths*, whereas the filenames being passed via the `...` are provided as *relative path(s)*. So during the `vapply()` step, the filenames (paths) do not match, and it doesn't know to exclude these "matching" files (i.e. `file %in% namex(excl)` evaluates to `FALSE`).
To work around this I have been able to:
1. use absolute paths in the original call, which is a bit tedious and doesn't appear to be what you had in mind considering the `relative_path =` argument defaults to `TRUE`.
2. I saw in the package README.md where you suggest configuring with a `.lintr` file with the exclusions supplied there in Debian Control Format. This DOES work! The paths do not get misaligned, so it's a slightly different behavior with passing via the `...`
**Questions**:
1. Am I using `lint_package` with exclusions as you intended?
2. I have some inconveniently long paths, so specifying relative paths (which from your examples you intended to be the case) would be ideal. Besides the package level config with `.lintr`, do you have any suggestions?
I realize there is a lot more going on under the hood, so I am sorry if this is not a simple work-around. I'd appreciate any advice. BTW, I absolutely **love** `lintr`, thank you so much for putting it together. I have been trying unify our group around common code style and practices for years ... I am hoping pre-commit hooks with `lintr` will get us there! ;)
Thank you so much,
Stu
It could be related as not fixed for expect_lint_free
...