setwd("~/docs/jesse-go-ermineJ3") library(rentrez) pmids<-unique(read.table("Pub_ids_str.txt")) getCiteCount<-function(pmid) { # don't spam Entrez Sys.sleep(runif(1)*2) # Fetch XML o<-entrez_link(db='pubmed', dbfrom='pubmed', retmode='xml', id=pmid, cmd='neighbor')$file # Grab field we want (as.numeric not really needed here) length(sapply(xpathApply(o, "//LinkSetDb[LinkName='pubmed_pubmed_citedin']/Link", xmlValue), as.numeric)) } #example getCiteCount(16007088) #test res<-sapply(pmids[1:2,], getCiteCount) names(res)<-as.character(pmids[1:2,]) # reset and run for real. res<-sapply(pmids[,1], getCiteCount) names(res)<-pmids write.table(res, file="Pub_ids_cites.txt", quote=F, sep='\t')