我正在尝试使用 RefManageR 和 PubMed ID (pmids) 从 PubMed 检索引文信息。
我选择了 RefManageR,因为它很容易以 data.frame 格式粘贴输出。对我来说,我自己仍然很难理解和使用 PubMed API。
我能够编写使用“PMId 字符串”作为输入来获取数据的代码:
require(RCurl)
urli <- getURL("https://gist.githubusercontent.com/aurora-mareviv/3840512f6777d5293218/raw/dfd6b76ceb22c52aa073fc05211dcea986406914/pmids.csv", ssl.verifypeer = FALSE)
pmids <- read.csv(textConnection(urli))
head(pmids)
index10 <- pmids$pmId[1:10]
indice10 <- paste(pmids$pmId[1:10], collapse=" ")
# install.packages("RefManageR")
library(RefManageR)
auth.pm10 <- ReadPubMed(indice10, database = "PubMed", mindate = 1950)
auth.pm10d <- data.frame(auth.pm10)
View(auth.pm10)
但是,如果我想从 500 pmids 获得引文,我想我应该避免在 PubMed 服务器中进行长查询。我的想法是创建一个循环遍历 vector 中所有元素的函数index10
,类似于:
extract.pub <-
function(id=indice, dbase=d.base, mindat=1950){
require(RefManageR)
indice <- id # Author
d.base <- dbase # like PubMed, etc
min.dat <- mindat # Date from...
auth.pm <- NULL
for(i in indice){
auth.pm <- ReadPubMed(indice, database = d.base, mindate = min.dat)
}
auth.pm <- data.frame(auth.pm)
auth.pm
}
cites <- extract.pub(index10, dbase="PubMed")
View(cites)
它给出以下错误:Error : Internal server error
。
但是,如果我插入indice10
(字符串)而不是index10
(向量),它会起作用:
cites <- extract.pub(indice10, dbase="PubMed")
View(cites)
¿我怎样才能使这个循环工作?或者这种方法对我的目的来说不是最好的?