## Search for scientific articles written by Damiano Fantini
## (via getPubmedIds() function), retrieve data from Entrez
## in XML format (via fetchPubmedData() function) and then
## print article titles to screen.
##
damiOnPubmed <- getPubmedIds("Damiano Fantini[AU]")
damiPapers <- fetchPubmedData(damiOnPubmed)
titles<- unlist(xpathApply(damiPapers, "//ArticleTitle", saveXML))
tPos <- regexpr("<ArticleTitle>.*<\\/ArticleTitle>", titles)
titles <- substr(titles, tPos + 14 , tPos + attributes(tPos)$match.length -16)
print(titles)
##
##
## In the following example, fetchPubmedData() is used in combination with
## custom retstart and retmax arguments. This shows how to download data
## from PubMed in batches of the desired size. This approach should be used
## when downloading a large number of records. The output should be the
## same as in the first example
##
myQuery <- getPubmedIds("Damiano Fantini[AU]")
myTitles <- c()
pubsNum <- myQuery$Count
myRetstart <- 0
myRetmax <- 4
while (myRetstart < pubsNum){
tmpPapers <- fetchPubmedData(myQuery, retstart = myRetstart, retmax = myRetmax)
tmpTitles <- unlist(xpathApply(tmpPapers, "//ArticleTitle", saveXML))
tPos <- regexpr("<ArticleTitle>.*<\\/ArticleTitle>", tmpTitles)
tmpTitles <- substr(tmpTitles, tPos + 14 , tPos + attributes(tPos)$match.length -16)
myTitles <- append(myTitles, tmpTitles)
myRetstart <- myRetstart + myRetmax
}
print(myTitles)
Run the code above in your browser using DataLab