Last active
July 16, 2021 06:48
-
-
Save noamross/89bc3e8c114b02bec09fd25272601a2c to your computer and use it in GitHub Desktop.
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(desc) | |
library(httr) | |
library(purrr) | |
library(stringi) | |
library(methods) | |
library(dplyr) | |
library(tidyr) | |
pkgs <- rownames(available.packages()) | |
if(!dir.exists("DESCRIPTIONS")) dir.create("DESCRIPTIONS") | |
walk(pkgs, function(p) { | |
if(!file.exists(paste0("DESCRIPTIONS/", p))) { | |
GET(paste0("https://raw.githubusercontent.com/cran/", p, "/master/DESCRIPTION"), | |
write_disk(paste0("DESCRIPTIONS/", p))) | |
} | |
}) | |
pd <- data_frame( | |
package = list.files("DESCRIPTIONS/"), | |
role = map(package, function(p) { | |
unique(stri_extract_all_regex( | |
desc_get("Author", paste0("DESCRIPTIONS/", p)), | |
"(?<=(\\[|,\\s))\\b[a-z]{3}\\b(?=(,|\\]))"))[[1]] | |
})) | |
tab <- pd %>% unnest() %>% | |
filter(!is.na(role)) %>% | |
group_by(package, role) %>% | |
summarize(n= n()) %>% | |
group_by() %>% | |
count(role) %>% | |
rename(pkgs_with=nn) %>% | |
left_join(utils:::MARC_relator_db, by=c("role"="code")) %>% | |
mutate(role = if_else(role %in% utils:::MARC_relator_db_codes_used_with_R, role, paste0(role, "*"))) %>% | |
arrange(desc(pkgs_with)) %>% | |
select(-usage, -description) %>% | |
rename(code = role, `CRAN packages with`=pkgs_with) %>% | |
pander::pander_return(style="grid", justify="left") | |
clipr::write_clip(tab) | |
pd %>% unnest() %>% | |
filter(!is.na(role), !(role %in% utils:::MARC_relator_db_codes_used_with_R), role != "rev") %>% | |
pander::pander_return(style="grid", justify="left") %>% clipr::write_clip() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another take at this 🙂
Created on 2021-07-16 by the reprex package (v2.0.0)