Skip to content

Instantly share code, notes, and snippets.

@gadenbuie
Forked from JBGruber/find_all_errors.R
Created July 17, 2021 19:30
Show Gist options
  • Save gadenbuie/747e9d276511a571dba7a9f4156bf2ce to your computer and use it in GitHub Desktop.
Save gadenbuie/747e9d276511a571dba7a9f4156bf2ce to your computer and use it in GitHub Desktop.
Find error messages of all installed packages
# get all packages
pkgs <- installed.packages()[, 1]
# make progress bar
pb <- progress::progress_bar$new(total = length(pkgs))
fcts <- purrr::map_df(pkgs, function(x) {
pb$tick()
# package must be attached to search it
sts <- try(
suppressMessages(
suppressPackageStartupMessages(
library(x, character.only = TRUE, quietly = TRUE)
)
), silent = TRUE
)
if (class(sts) != "try-error") {
# lsf.str() to search functions
fs <- as.character(lsf.str(paste0("package:", x)))
# body() to get definition
ds <- purrr::map_chr(fs, ~ paste(as.character(body(.x)), collapse = " "))
# extract stop() messages
ers <- stringi::stri_extract_all_regex(
ds,
"(?<=stop\\().*?(?=\\))"
)
# detach package in case of conflicts
suppressWarnings(
try(
detach(
name = paste0("package:", x), unload = TRUE, character.only = TRUE
), silent =TRUE
)
)
} else {
ds <- fs <- "can't load package"
ers <- as.list(ds)
}
return(tibble::tibble(
package = x,
function_name = fs,
definition = ds,
error_message = ers
))
})
library(tidyverse)
error_message_df <- fcts %>%
unnest(error_message) %>%
filter(!is.na(error_message), !duplicated(error_message))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment