Created
August 12, 2017 00:04
-
-
Save karthik/c1ab47b1c8d472de96595327028cbdf1 to your computer and use it in GitHub Desktop.
This file contains 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(rAltmetric) | |
library(purrr) | |
# we launch purrr because it gives us the safely function | |
ids <- c("10.1371/journal.pbio.0000002", | |
"10.1371/journal.pbio.0000003", | |
"10.1371/journal.pbio.0000004", | |
"10.1371/journal.pbio.0000005", | |
"10.1371/journal.pbio.0000006", | |
"10.1371/journal.pbio.0000007", | |
"10.1371/journal.pbio.0000008", | |
"10.1371/journal.pbio.0000009" | |
) | |
ids2 <- as.list(ids) | |
safe_metrics <- safely(altmetrics) | |
metric_data <- function(x) { | |
alm <- safe_metrics(doi = x) | |
# Safely ensures that the function returns NULL if nothing else comes out | |
if(is.null(alm$result)) { | |
NULL | |
} else { | |
data.frame(t(unlist(alm$result)), stringsAsFactors = FALSE) | |
} | |
} | |
results <- lapply(ids2, metric_data) | |
# This next bit removes NULL (ie. dois for which there were no metrics) | |
results <- Filter(Negate(is.null), results) | |
# Now this is a list of lists. You can flatten now as you please | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment