在 R (httr) 中使用 pubmed api 来检索摘要 [英] Working with pubmed api in R (httr) to retrieve abstracts
问题描述
我正在尝试使用 httr
直接使用来自 R 的 pubmed
api.有一些优秀的包可用,例如 RISmed
和 easypubmed
但对于这个特定的任务,我需要直接与 api 交互.
I am trying to work directly with the pubmed
api from R using httr
. There are excellent packages available such as RISmed
and easypubmed
but for this particular task, I need to interact directly with the api.
使用这组说明(https://www.ncbi.nlm.nih.gov/books/NBK25500/),我从这个代码开始,但返回的是一个没有任何细节或pmid
的列表.任何指导表示赞赏.或者如果您知道在此设置中使用 R 的特定教程.
Using this set of instructions (https://www.ncbi.nlm.nih.gov/books/NBK25500/), I started with this code but the returned is a list without any details or pmid
. Any guidance is appreciated. or if you are aware of particular tutorials on using R in this setting.
library(XML)
library(httr)
library(glue)
query = 'asthma[mesh]+AND+leukotrienes[mesh]+AND+2009[pdat]'
reqq = glue ('https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term={query}')
op = GET(reqq)
我也尝试了这篇文章中的代码(为什么我得到这个错误:XML 内容似乎不是 XML),但它给出了这个错误 Error in read_xml.raw(x, encoding = encoding,...) : 开始和结束标签不匹配:meta line 17 and head [76]
I also tried the code from this post (why i get that error : XML content does not seem to be XML), but it give this error Error in read_xml.raw(x, encoding = encoding, ...) : Opening and ending tag mismatch: meta line 17 and head [76]
推荐答案
您可以读取 XML 响应并解析它以收集发布的 ID,例如:
You can read XML response and parse it to collect pubmed IDs, for instance:
library(magrittr)
df_op <- op %>% xml2::read_xml() %>% xml2::as_list()
pmids <- df_op$eSearchResult$IdList %>% unlist(use.names = FALSE)
给出:
> pmids
[1] "20113659" "20074456" "20046412" "20021457" "20008883" "20008181" "19912318" "19897276" "19895589"
[10] "19894390" "19852204" "19839969" "19811112" "19757309" "19749079" "19739647" "19706339" "19665766"
[19] "19648384" "19647860"
这篇关于在 R (httr) 中使用 pubmed api 来检索摘要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!