Created
October 10, 2024 19:17
-
-
Save EmilHvitfeldt/45b03be72cc764e4ceff87d704f06d3c to your computer and use it in GitHub Desktop.
Count all message, warnings, and errors in R package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
counter <- function(fun) { | |
function(x) { | |
r_files <- fs::dir_ls(fs::path(x, "R")) | |
excludes <- stringr::str_detect( | |
basename(r_files), | |
"^(deprecated|import)-", | |
negate = TRUE | |
) | |
r_files[excludes] |> | |
purrr::map(readLines) |> | |
unlist() |> | |
stringr::str_detect(paste0(fun, "\\(")) |> | |
sum() | |
} | |
} | |
n_cli_abort <- function(x) counter("cli_abort")(x) | |
n_cli_warn <- function(x) counter("cli_warn")(x) | |
n_cli_inform <- function(x) counter("cli_inform")(x) | |
n_abort <- function(x) counter("abort")(x) | |
n_warn <- function(x) counter("warn")(x) | |
n_inform <- function(x) counter("inform")(x) | |
n_stop <- function(x) counter("stop")(x) | |
n_warning <- function(x) counter("warning")(x) | |
n_message <- function(x) counter("message")(x) | |
report <- function(x = ".") { | |
path <- fs::path(x) | |
tibble::tibble( | |
package = x, | |
cli_abort = n_cli_abort(path), | |
cli_warn = n_cli_warn(path), | |
cli_inform = n_cli_inform(path), | |
abort = n_abort(path) - n_cli_abort(path), | |
warn = n_warn(path) - n_cli_warn(path), | |
inform = n_inform(path) - n_cli_inform(path), | |
stop = n_stop(path), | |
warning = n_warning(path), | |
message = n_message(path) | |
) |> | |
dplyr::glimpse() | |
} | |
report() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment