Skip to content

Instantly share code, notes, and snippets.

@mathzero
Last active October 4, 2022 18:33
Show Gist options
  • Save mathzero/f1d1b3b94f6f76019a5861d1bed7d597 to your computer and use it in GitHub Desktop.
Save mathzero/f1d1b3b94f6f76019a5861d1bed7d597 to your computer and use it in GitHub Desktop.
Hacky fix for rAltmetrics function
altmetrics_new <-
function(doi = NULL,
apikey = NULL,
...) {
base_url <- "https://api.altmetric.com/v1/"
args <- list(key = apikey)
request <-
httr::GET(paste0(base_url, "doi/",doi))
if(httr::status_code(request) == 404) {
stop("No metrics found for object")
} else {
httr::warn_for_status(request)
results <-
jsonlite::fromJSON(httr::content(request, as = "text"), flatten = TRUE)
results <- rlist::list.flatten(results)
class(results) <- "altmetric"
results
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment