Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attenuate the verbosity in lint_package() #260

Closed
wlandau opened this issue Aug 23, 2017 · 3 comments
Closed

Attenuate the verbosity in lint_package() #260

wlandau opened this issue Aug 23, 2017 · 3 comments

Comments

@wlandau
Copy link
Contributor

wlandau commented Aug 23, 2017

In lint_package(), it would be nice to have an option to condense the output. Rather than print out every lint, sometimes I may want to print the number of lints per file and omit all the clean files. I am picturing something like print(covr::package_coverage()).

@jimhester
Copy link
Member

I think all you would need was to define a summary.lints() method. This seems to do the job

summary.lints <- function(object, ...) {
  filenames <- vapply(object, `[[`, character(1), "filename")
  types <- factor(vapply(object, `[[`, character(1), "type"), levels = c("style", "warning", "error"))
  tbl <- table(filenames, types)
  filenames <- rownames(tbl)
  res <- as.data.frame.matrix(tbl, stringsAsFactors = FALSE, row.names = FALSE)
  res$filenames <- filenames
  nms <- colnames(res)
  res[order(-res$error, -res$warning, -res$style), c("filenames", nms[nms != "filenames"])]
}

head(n = 15, 
  summary(package_lints("devtools")))
#>                             filenames style warning error
#> 23                 R/install-github.r     6       4     0
#> 26                    R/install-svn.r     7       2     0
#> 12                         R/doctor.R     5       2     0
#> 15                            R/git.R     5       2     0
#> 32                        R/release.r     7       1     0
#> 28                R/install-version.r     5       1     0
#> 45                            R/zzz.r     3       1     0
#> 20              R/install-bitbucket.r     2       1     0
#> 10                     R/decompress.r     1       1     0
#> 30                        R/package.r     1       1     0
#> 25                 R/install-remote.R    50       0     0
#> 50       tests/testthat/test-github.r    45       0     0
#> 47 tests/testthat/test-bioconductor.r    19       0     0
#> 11                           R/deps.R    17       0     0
#> 54      tests/testthat/test-remotes.r    10       0     0

@wlandau
Copy link
Contributor Author

wlandau commented Aug 26, 2017

Thank you @jimhester, this is exactly what I am after. Could this function become part of lintr itself, or should I plan to use it on its own?

@jimhester
Copy link
Member

Sure it could be, if you would like to open a PR with the above I can review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants