Created
June 5, 2025 14:27
-
-
Save EmilHvitfeldt/3b8a45acd97caa553367c8bc4453f158 to your computer and use it in GitHub Desktop.
get all badges from tidymodels packages
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
library(tidymodels) | |
tm_pkgs <- setdiff( | |
tidymodels::tidymodels_packages(), | |
tidyverse::tidyverse_packages() | |
) | |
get_badge_order <- function(pkg) { | |
url <- glue::glue( | |
"https://raw.githubusercontent.com/tidymodels/{pkg}/refs/heads/main/README.Rmd" | |
) | |
readme <- readr::read_lines(url) | |
start <- which(stringr::str_detect(readme, "badges: start")) | |
end <- which(stringr::str_detect(readme, "badges: end")) | |
if (length(start) < 1) { | |
return( | |
tibble( | |
pkg = character(), | |
badge = character(), | |
order = integer() | |
) | |
) | |
} | |
badges <- readme[seq(start + 1, end - 1)] | |
badges <- badges[badges != ""] | |
badges <- stringr::str_extract(badges, "\\[.*?\\]") | |
badges <- stringr::str_remove_all(badges, "[\\[\\]!]") | |
tibble( | |
pkg = pkg, | |
badge = badges, | |
order = seq_along(badge) | |
) | |
} | |
badge_info <- map(tm_pkgs, get_badge_order) | |
no_fences <- tm_pkgs[map_int(badge_info, nrow) == 0] | |
bind_rows(badge_info) |> | |
mutate(dup = duplicated(badge), .by = pkg) |> | |
filter(!dup) |> | |
select(-dup) |> | |
pivot_wider(names_from = badge, values_from = order) |> | |
View() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment