Last active
November 22, 2015 13:53
-
-
Save tts/a6fd3aa47097b2c888c7 to your computer and use it in GitHub Desktop.
Most discussed articles on diabetes in 2015
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(RCurl) | |
| library(rAltmetric) | |
| library(dplyr) | |
| # Which articles on diabetes, published in 2015, are among the most discussed based on Altmetric.com data? | |
| # See http://tuijasonkkila.fi/blog/2015/11/diabetes/ | |
| # http://www.fredtrotter.com/2014/11/14/hacking-on-the-pubmed-api/ | |
| baseurl <- "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&retmode=json&retmax=1000&term=" | |
| # Advanced search query details, http://www.ncbi.nlm.nih.gov/pubmed/advanced | |
| advq <- '"diabetes mellitus"[MeSH Terms] AND ("2015/01/01"[PDAT] : "3000"[PDAT])' | |
| advq_encoded <- URLencode(advq) | |
| q <- paste0(baseurl,advq_encoded) | |
| res <- getURLContent(q) | |
| res_parsed <- jsonlite::fromJSON(res) | |
| ids <- res_parsed$esearchresult$idlist | |
| ids2 <- paste("pmid/", ids, sep = "") | |
| # Query Altmetric API | |
| raw_metrics <- llply(ids2, altmetrics, .progress = 'text') | |
| metric_data <- ldply(raw_metrics, altmetric_data) | |
| # Sort by Altmetric score | |
| sorted_by_score <- metric_data[with(metric_data, order(score, decreasing=T)), ] | |
| # Filter columns | |
| topscore <- sorted_by_score %>% | |
| select (title,url,score,details_url) | |
| write.csv(topscore, file = "diabetes2015_topAltmetricScore.csv", row.names = F) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment