Я действительно новичок в XML. Мне нужно построить сетевой график, поэтому я пытаюсь получить информацию из PubMed. Я осмотрелся и нашел код, однако в коде есть некоторые проблемы.
Вот код
pubmedSearch <- entrez_search(db="pubmed", term="Nabin Poudel[AUTH]")
SearchResults<-entrez_fetch(db="pubmed", npoudel$ids, rettype="xml", parsed=TRUE)
parse_author <- function(author){
fn <- xmlValue(author[["ForeName"]])
ln <- xmlValue(author[["LastName"]])
aff <-paste(xpathApply(author, "AffiliationInfo/Affiliation", xmlValue), collapse="; ")
list(forname=fn, lastname=ln, affiliation=aff)
}
parse_paper <- function(paper){
author_info <- xpathApply(paper, ".//AuthorList/Author", parse_author)
res <- do.call(rbind.data.frame, author_info)
if (length(res)==0){
res <- data.frame(forname=NA,lastname=NA, affiliation=NA)
}
res$pmid <-xpathSApply(paper, ".//ArticleId[@IdType='pubmed']", xmlValue)
res
}
parse_multiple_papers <- function(papers){
res <- xpathApply(papers, "/PubmedArticleSet/*", parse_paper)
do.call(rbind.data.frame, res)
}
head(parse_multiple_papers(SearchResults))
this is the error I am having
> head(parse_multiple_papers(SearchResults))
Error in `$<-.data.frame`(`*tmp*`, pmid, value = c("31502239", "21492271", :
replacement has 38 rows, data has 3