Skip to content

Instantly share code, notes, and snippets.

@EmilHvitfeldt
Last active November 16, 2023 00:52
Show Gist options
  • Save EmilHvitfeldt/0731497636221aa2d5db22e0dccd0774 to your computer and use it in GitHub Desktop.
Save EmilHvitfeldt/0731497636221aa2d5db22e0dccd0774 to your computer and use it in GitHub Desktop.
count of current usage of error, warning, or message functions from {base}, {rlang} and {cli}
``` r
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("~/Github/", 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)
)
}
packages <- tidymodels::tidymodels_packages() |>
setdiff(tidyverse::tidyverse_packages())
options(width=205)
packages |>
purrr::map(report) |>
purrr::list_rbind()
#> # A tibble: 12 × 10
#> package cli_abort cli_warn cli_inform abort warn inform stop warning message
#> <chr> <int> <int> <int> <int> <int> <int> <int> <int> <int>
#> 1 dials 0 0 0 68 6 1 1 0 0
#> 2 hardhat 18 0 0 52 4 0 0 0 0
#> 3 infer 0 0 0 0 0 0 1 1 1
#> 4 modeldata 0 0 0 3 0 0 0 0 0
#> 5 parsnip 3 3 0 230 46 0 13 0 9
#> 6 recipes 3 0 0 185 40 0 16 0 2
#> 7 rsample 5 0 0 133 14 0 0 0 0
#> 8 tune 13 1 2 146 23 2 0 5 9
#> 9 workflows 0 0 0 65 10 0 0 0 0
#> 10 workflowsets 0 0 0 17 8 0 0 1 7
#> 11 yardstick 0 0 0 111 12 0 4 0 2
#> 12 tidymodels 0 0 0 2 0 0 0 0 3
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment