@@ -96,9 +96,14 @@ chunk <- function(x,n) split(x, factor(sort(rank(x)%%n)))
9696# '
9797# ' @param pmids An array of Pubmed IDs
9898# ' @param cache_pmid_fname File with retrieved citation data (.rds)
99+ # ' @param chunk_size Size of chunks to be processed (
100+ # ' max 400 due to EUtils limit)
99101# ' @return citation PubMed citation, with first author, journal and year
100102# '
101- get_citations_pubmed <- function (pmids , cache_pmid_fname = NA ){
103+ get_citations_pubmed <- function (
104+ pmids ,
105+ cache_pmid_fname = NA ,
106+ chunk_size = 100 ){
102107
103108 pmid_df <- data.frame (' pmid' = pmids )
104109 cache_citations <- data.frame ()
@@ -123,11 +128,10 @@ get_citations_pubmed <- function(pmids, cache_pmid_fname = NA){
123128 }else {
124129 all_citations <- cache_citations
125130 }
126-
127131 pmids <- pmid_df $ pmid
128132
129133 # # make chunk of maximal 400 PMIDs from input array (limit by EUtils)
130- pmid_chunks <- chunk(pmids ,ceiling(length(pmids )/ 100 ))
134+ pmid_chunks <- chunk(pmids ,ceiling(length(pmids )/ chunk_size ))
131135 j <- 0
132136 cat(' Retrieving PubMed citations for PMID list, total length' ,
133137 length(pmids ))
@@ -146,9 +150,21 @@ get_citations_pubmed <- function(pmids, cache_pmid_fname = NA){
146150 i <- 1
147151 first_author <- c()
148152 while (i < = length(authorlist )) {
149- first_author <- c(first_author ,
150- paste(authorlist [[i ]][1 ,]$ LastName ,
151- " et al." , sep = " " ))
153+ if (length(authorlist [[i ]]) == 5 ) {
154+ if (! is.na(authorlist [[i ]][1 ,]$ LastName )){
155+ first_author <- c(first_author ,
156+ paste(authorlist [[i ]][1 ,]$ LastName ,
157+ " et al." , sep = " " ))
158+ }
159+ if (is.na(authorlist [[i ]][1 ,]$ LastName ) &
160+ ! is.na(authorlist [[i ]][1 ,]$ CollectiveName )){
161+ first_author <- c(
162+ first_author ,
163+ authorlist [[i ]][1 ,]$ CollectiveName )
164+ }
165+ }else {
166+ first_author <- c(first_author , " Unknown et al." )
167+ }
152168 i <- i + 1
153169 }
154170 journal <- RISmed :: ISOAbbreviation(result )
0 commit comments