Skip to content

Instantly share code, notes, and snippets.

@EmilHvitfeldt
Last active October 20, 2024 16:51
Show Gist options
  • Save EmilHvitfeldt/13530c687cbd7975e4ac51fb1f9ddc49 to your computer and use it in GitHub Desktop.
Save EmilHvitfeldt/13530c687cbd7975e4ac51fb1f9ddc49 to your computer and use it in GitHub Desktop.
find untested cli code in R package
library(tidyverse)
# https://github.com/r-lib/covr/issues/482
res_tbl <- devtools::test_coverage() |>
purrr::map(~tibble(
value = if_else(is.null(.x$value), NA, .x$value),
code = as.character(.x$srcref)
)) |>
purrr::list_rbind(names_to = "file")
# Tibble output
res_tbl |>
filter(value == 0, str_detect(code, "(cli_abort|cli_warn|cli_inform)")) |>
arrange(file)
# Cleaned up version
res_tbl |>
filter(value == 0, str_detect(code, "(cli_abort|cli_warn|cli_inform)")) |>
arrange(file) |>
mutate(file = str_extract(file, ".*?:.*?:")) |>
mutate(file = str_remove(file, ":$")) |>
pull(file) |>
cat(sep = "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment