Skip to content

Commit

Permalink
update paper machine and papers
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Jun 18, 2024
1 parent 5d02015 commit 8b59a39
Show file tree
Hide file tree
Showing 3 changed files with 367 additions and 222 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/update-publications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,40 @@ jobs:
bib <- paste(c(bib_old, bib_new), collapse = "\n")
write(bib, "_data/papers.bib")
## filter latest version
df <- bib2df("_data/papers.bib") |>
dplyr::mutate(
version = dplyr::if_else(
grepl("wellcomeopenres", DOI),
sub("^.*\\.([1-9][0-9]*)$", "\\1", DOI),
"1"
),
base_doi = dplyr::if_else(
grepl("wellcomeopenres", DOI),
sub("\\.([1-9][0-9]*)$", "", DOI),
DOI
)
) |>
dplyr::group_by(base_doi) |>
dplyr::filter(version == max(version)) |>
dplyr::ungroup() |>
dplyr::select(-base_doi, -version)
## filter preprints
df <- df |>
dplyr::group_by(TITLE) |>
dplyr::mutate(n = dplyr::n()) |>
dplyr::mutate(id = seq_len(dplyr::n())) |>
dplyr::mutate(n_pp = sum(JOURNAL == "medRxiv")) |>
dplyr::filter(
!((n_pp < n) & (JOURNAL == "medRxiv"))
) |>
dplyr::filter(
!(n > 1 & id < max(id))
) |>
dplyr::ungroup()
shell: Rscript {0}

- uses: peter-evans/create-pull-request@v6
Expand Down
58 changes: 41 additions & 17 deletions _automation/get_new_papers.R
Original file line number Diff line number Diff line change
@@ -1,37 +1,55 @@
`%>%` <- magrittr::`%>%`

get_new_papers_orcid <- function(orcid, from_date) {

rcrossref::cr_works(filter = list(orcid = orcid,
from_deposit_date = from_date,
type = "journal-article")) %>%
refs <- rcrossref::cr_works(filter = list(
orcid = orcid,
from_deposit_date = from_date
)) |>
purrr::pluck("data")


if (nrow(refs) > 0) {
refs <- refs |>
dplyr::mutate(
container.title = dplyr::if_else(
publisher == "Cold Spring Harbor Laboratory",
"medRxiv",
container.title
),
type = dplyr::if_else(
publisher == "Cold Spring Harbor Laboratory",
"journal-article",
type
)
) |>
dplyr::filter(type == "journal-article")
existing_papers <- dois_from_bib("_data/papers.bib")
refs <- refs |>
dplyr::filter(!(doi %in% existing_papers))
}
return(refs)
}

get_new_papers_team <- function(from_date) {

recent_papers <- fs::dir_ls("_data/team", regexp = "\\w+\\-\\w+\\.yml") %>%
purrr::map(yaml::read_yaml) %>%
purrr::keep(function(x) x[["current-member"]]) %>%
purrr::map("orcid") %>%
purrr::keep(~ !is.null(.x)) %>%
purrr::map_dfr(get_new_papers_orcid, from_date = from_date) %>%
recent_papers <- fs::dir_ls("_data/team", regexp = "\\w+\\-\\w+\\.yml") |>
purrr::map(yaml::read_yaml) |>
purrr::keep(function(x) x[["current-member"]]) |>
purrr::map("orcid") |>
purrr::keep(~ !is.null(.x)) |>
purrr::map_dfr(get_new_papers_orcid, from_date = from_date) |>
dplyr::distinct()

return(recent_papers)

}

create_bibentries <- function(papers) {
papers %>%
papers |>
dplyr::mutate(
author = purrr::map(author, ~ dplyr::filter(.x, !is.na(given) &!is.na(family))),
author = purrr::map(author, ~ paste(.x$given, .x$family)),
author = purrr::map(author, as.person),
year = format(lubridate::parse_date_time(issued, c("Y-m-d", "Y-m", "Y")), "%Y")
) %>%
dplyr::rowwise() %>%
) |>
dplyr::rowwise() |>
dplyr::mutate(
bib = list(bibentry(
"Article",
Expand All @@ -42,7 +60,13 @@ create_bibentries <- function(papers) {
doi = doi,
key = ids::adjective_animal()
))
) %>%
) |>
dplyr::pull(bib)

}

dois_from_bib <- function(bib) {
bib |>
bibtex::read.bib() |>
purrr::map_chr(~ .x$doi)
}
Loading

0 comments on commit 8b59a39

Please sign in to comment.