Skip to content

Instantly share code, notes, and snippets.

@gadenbuie
Last active November 1, 2015 05:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gadenbuie/9b5609a6154753394f1a to your computer and use it in GitHub Desktop.
Save gadenbuie/9b5609a6154753394f1a to your computer and use it in GitHub Desktop.
Look up citation counts with rcrossref
getCiteCounts <- function(citekeys, bibtex){
## This function takes a list of citation keys, for ex. from lit review notes
## and a master bibtex file with citekeys and DOIs
## Returns a vector of number of times each article was cited from CrossRef
# Check for and load/install required packages
# --> stringr, rcrossref
if (!'stringr' %in% installed.packages()) install.packages('stringr')
require(stringr, quietly=TRUE)
if (!'rcrossref' %in% installed.packages()){
if(!'devtools' %in% installed.packages()) install.packages('devtools')
devtools::install_github('ropensci/rcrossref')
}
require(rcrossref)
# Load and parse bibtex file pulling out citation keys and DOIs only
keys <- c()
dois <- c()
pass <- FALSE
lib <- file(bibtex, open='r')
for(line in readLines(lib, warn=F)){
if(str_sub(str_trim(tolower(line)), 1, 9) == '@preamble'){
pass <- TRUE
} else if (str_trim(line) == '"}'){
pass <- FALSE
}
if(pass) next
if(str_sub(line, 1, 1) == '@'){
key <- str_match(line, "@\\w+[\\{]([^\\,]+)[\\,]")[1,2]
doi <- ''
}
if(str_sub(str_trim(line), 1,3) == 'doi'){
doi <- str_split(line, '\\{|\\}')[[1]][2]
}
if(line == '}'){
keys <- c(keys, key)
dois <- c(dois, doi)
}
}
close(lib)
biblib <- dois
names(biblib) <- keys
getCites <- function(key){
# Helper function to look up citation key on CrossRef
# Does its best to handle blank keys and missing DOIs
if(key == ''){
return(NA)
}
doi <- biblib[key]
if(is.na(doi)){
print(paste('Citekey not found in bibfile:', key))
return(NA)
} else if (doi == ''){
return(NA)
}
cites <- cr_citation_count(doi)
if(!is.numeric(cites)){
return(NA)
} else {
return(cites)
}
}
cites <- rep(NA, length(citekeys))
for(i in 1:length(citekeys)){
cites[i] <- getCites(citekeys[i])
}
return(cites)
}
####---- How To Use ----####
## Load a csv with your research notes (indexed by citekey)
# litdata <- read.csv('path/to/your/file', stringsAsFactors = FALSE)
## Point R at your Master BibTeX file
# MasterBibtex <- 'path/to/bibtex.lib'
## Use getCiteCounts to add citation counts as a new column
# litdata$Citations <- getCiteCounts(litdata$Citekey, MasterBibtex)
## Win!
####---- Demo ----####
extable <- read.csv('test.csv', stringsAsFactors = FALSE)
MasterBibtex <- 'test.bib'
extable$Citations <- getCiteCounts(extable$Citekey, MasterBibtex)
@article{Ripamonti2009,
author = {Ripamonti, Carla Ida and Farina, Gabriella and Garassino, Marina Chiara},
doi = {10.1002/cncr.24351},
journal = {Cancer},
number = {S13},
pages = {3128--3134},
title = {{Predictive models in palliative care}},
url = {http://dx.doi.org/10.1002/cncr.24351},
volume = {115},
year = {2009}
}
@article{Kaizhu2006,
author = {Kaizhu, Huang and Haiqin, Yang and Irwin, King and Lyu, M R},
doi = {10.1109/tbme.2006.872819},
journal = {Biomedical Engineering, IEEE Transactions on},
number = {5},
pages = {821--831},
title = {{Maximizing sensitivity in medical diagnosis using biased minimax probability Machine}},
volume = {53},
year = {2006}
}
@article{Own2012,
author = {Own, Hala S. and Abraham, Ajith},
doi = {10.1016/j.asoc.2011.11.025},
journal = {Applied Soft Computing},
month = mar,
number = {3},
pages = {999--1005},
publisher = {Elsevier B.V.},
title = {{A new weighted rough set framework based classification for Egyptian NeoNatal Jaundice}},
url = {http://linkinghub.elsevier.com/retrieve/pii/S1568494611004674},
volume = {12},
year = {2012}
}
@article{Dick2009,
author = {Dick, Thomas E and Baekey, David M and Paton, Julian F R and Lindsey, Bruce G and Morris, Kendall F},
doi = {10.1016/j.resp.2009.07.009},
journal = {Respiratory physiology \& neurobiology},
month = aug,
number = {1-2},
pages = {76--85},
title = {{Cardio-respiratory coupling depends on the pons.}},
url = {http://www.ncbi.nlm.nih.gov/pubmed/19643216},
volume = {168},
year = {2009}
}
@article{Allahviranloo2014,
author = {Allahviranloo, Mahdieh and Chow, Joseph Y.J. and Recker, Will W.},
doi = {10.1016/j.tre.2013.12.004},
journal = {Transportation Research Part E: Logistics and Transportation Review},
pages = {68--88},
title = {{Selective vehicle routing problems under uncertainty without recourse}},
url = {http://www.sciencedirect.com/science/article/pii/S1366554513001981},
volume = {62},
year = {2014}
}
@article{Yue2006,
author = {Yue, Dongxia and Xu, Xiaofeng and Li, Zizhen and Hui, Cang and Li, Wenlong and Yang, Hequn and Ge, Jianping},
doi = {10.1016/j.ecolecon.2005.07.029},
journal = {Ecological Economics},
month = jun,
number = {2},
pages = {393--406},
title = {{Spatiotemporal analysis of ecological footprint and biological capacity of Gansu, China 1991–2015: Down from the environmental cliff}},
url = {http://linkinghub.elsevier.com/retrieve/pii/S0921800905003290},
volume = {58},
year = {2006}
}
@article{Odum2000,
author = {Odum, Howard T. and Odum, Eugene P.},
doi = {10.1007/s100210000005},
journal = {Ecosystems},
month = jan,
number = {1},
pages = {21--23},
title = {{The Energetic Basis for Valuation of Ecosystem Services}},
url = {http://www.springerlink.com/openurl.asp?genre=article\&id=doi:10.1007/s100210000005},
volume = {3},
year = {2000}
}
@article{Huh2013,
author = {Huh, Jina and Le, Thai and Reeder, Blaine and Thompson, Hilaire J and Demiris, George},
doi = {10.1016/j.ijmedinf.2013.08.009},
journal = {International journal of medical informatics},
month = nov,
number = {11},
pages = {1092--103},
publisher = {Elsevier Ireland Ltd},
title = {{Perspectives on wellness self-monitoring tools for older adults.}},
url = {http://www.ncbi.nlm.nih.gov/pubmed/24041452},
volume = {82},
year = {2013}
}
@article{Hug2004,
author = {Hug, Florian and Bader, Hans-Peter and Scheidegger, Ruth and Baccini, Peter},
doi = {10.1007/s10098-003-0230-y},
journal = {Clean Technologies and Environmental Policy},
month = apr,
number = {2},
pages = {138--148},
title = {{A dynamic model to illustrate the development of an interregional energy household to a sustainable status}},
url = {http://www.springerlink.com/openurl.asp?genre=article\&id=doi:10.1007/s10098-003-0230-y},
volume = {6},
year = {2004}
}
@article{Feng2006,
author = {Feng, Li and Liu, Ziyan},
doi = {10.1109/PES.2006.1709073},
journal = {2006 IEEE Power Engineering Society General Meeting},
pages = {6 pp.},
publisher = {Ieee},
title = {{Genetic algorithms and rough fuzzy neural network-based hybrid approach for short-term load forecasting}},
url = {http://ieeexplore.ieee.org/lpdocs/epic03/wrapper.htm?arnumber=1709073},
year = {2006}
}
@article{Calabrese2011,
author = {Calabrese, Francesco and Colonna, Massimo and Lovisolo, Piero and Parata, Dario and Ratti, Carlo},
doi = {10.1109/TITS.2010.2074196},
journal = {IEEE Transactions on Intelligent Transportation Systems},
month = mar,
number = {1},
pages = {141--151},
title = {{Real-Time Urban Monitoring Using Cell Phones: A Case Study in Rome}},
url = {http://ieeexplore.ieee.org/lpdocs/epic03/wrapper.htm?arnumber=5594641},
volume = {12},
year = {2011}
}
@article{Vielma2012,
author = {Vielma, J.P. and Ahmed, S. and Nemhauser, G.L.},
doi = {10.1016/j.orl.2012.01.007},
journal = {Operations Research Letters},
month = may,
number = {3},
pages = {153--158},
title = {{Mixed integer linear programming formulations for probabilistic constraints}},
url = {http://www.sciencedirect.com/science/article/pii/S0167637712000168},
volume = {40},
year = {2012}
}
@article{Dietterich2000,
author = {Dietterich, Thomas G.},
journal = {Multiple classifier systems},
title = {{Ensemble methods in machine learning}},
url = {http://www.springerlink.com/index/LG5742LR8810612K.pdf},
year = {2000}
}
@article{Nitzsche2014,
author = {Nitzsche, T and Thiele, S and H\"{a}ber, a and Winter, a},
doi = {10.3414/ME13-02-0010},
journal = {Methods of information in medicine},
month = jan,
number = {3},
pages = {167--72},
title = {{Communication architecture for AAL. Supporting patient care by health care providers in AAL-enhanced living quarters.}},
url = {http://www.ncbi.nlm.nih.gov/pubmed/24728125},
volume = {53},
year = {2014}
}
@article{Lucas1999,
author = {Lucas, PJF Peter J F and Abu-Hanna, Ameen},
doi = {10.1016/s0933-3657(98)00047-5},
journal = {Artificial Intelligence in Medicine},
number = {2},
pages = {105--119},
title = {{Prognostic methods in medicine}},
url = {http://igitur-archive.library.uu.nl/math/2007-0104-200831/abu-hanna\_97\_prosnostic.pdf http://www.sciencedirect.com/science/article/pii/S0933365798000475},
volume = {15},
year = {1999}
}
@article{Dawson1991,
author = {Dawson, Norma Jean},
doi = {10.1016/0277-9536(91)90131-u},
journal = {Social Science \&amp; Medicine},
number = {1},
pages = {83--87},
title = {{Need satisfaction in terminal care settings}},
url = {http://www.sciencedirect.com/science/article/pii/027795369190131U},
volume = {32},
year = {1991}
}
@article{Ludwig2012,
author = {Ludwig, Wolfram and Wolf, Klaus-Hendrik and Duwenkamp, Christopher and Gusew, Nathalie and Hellrung, Nils and Marschollek, Michael and Wagner, Markus and Haux, Reinhold},
doi = {10.1016/j.cmpb.2011.11.001},
journal = {Computer methods and programs in biomedicine},
month = may,
number = {2},
pages = {70--8},
publisher = {Elsevier Ireland Ltd},
title = {{Health-enabling technologies for the elderly--an overview of services based on a literature review.}},
url = {http://www.ncbi.nlm.nih.gov/pubmed/22115611},
volume = {106},
year = {2012}
}
Citekey Author Year Read
Kaizhu2006 Kaizhu 2006 No
Ripamonti2009 Ripamonti 2009 Yes
Own2012 Own 2012 No
Dick2009 Dick 2009 No
Allahviranloo2014 Allahviranloo 2014 Yes
Yue2006 Yue 2006 No
Odum2000 Odum 2000 Yes
Huh2013 Huh 2013 No
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment