Skip to content

Instantly share code, notes, and snippets.

@karthik
Last active May 18, 2022 18:36
Show Gist options
  • Save karthik/78016fc78d52156561f5f543defb7ec0 to your computer and use it in GitHub Desktop.
Save karthik/78016fc78d52156561f5f543defb7ec0 to your computer and use it in GitHub Desktop.
library(rAltmetric)
library(tidyverse)
ids <- list(
"10.1016/j.kint.2017.06.017",
"10.1016/j.kint.2017.08.025",
"10.1016/j.kint.2017.07.024",
"10.1016/j.kint.2017.09.013",
"10.1016/j.kint.2017.06.026",
"10.1016/j.kint.2017.06.022",
"10.1016/j.kint.2017.06.025",
"10.1016/j.kint.2017.06.028",
"10.1016/j.kint.2017.09.028",
"10.1016/j.kint.2017.11.011",
"10.1016/j.kint.2017.11.022",
"10.1016/j.kint.2017.12.003"
)
# Safely allows you to wrap any function around it and capture errors
# In this case we return NULL when the API does not find a DOI
safe_altmetrics <- purrr::safely(altmetrics, otherwise = NULL)
alm <- function(x) safe_altmetrics(doi = x)
# Now we make the API call
requests <- map(ids, alm)
# There are 12 DOIs but there is only data for 5.
# We map the result item from the inner list,
# remove the NULL ones
# then run the altmeric_data on the result objects
results <- requests %>%
map("result") %>%
compact(.) %>%
modify_depth(1, altmetric_data)
data <- bind_rows(results) %>% select(doi, contains("cited"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment