Skip to content

Commit

Permalink
Ensure pubmed records are assigned only one PMID
Browse files Browse the repository at this point in the history
Prior to this commit, pubmed records hat contained a lit of cited papers
could generate a "pmid" field in teh pubmed record that included all
pmids. This commit fixes bug #131 and provides a test against
regression.

Thanks @agbarnett for the bug report
  • Loading branch information
dwinter committed May 2, 2019
1 parent 3adee45 commit 991c555
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/parse_pubmed_xml.r
Expand Up @@ -58,8 +58,8 @@ parse_one_pubmed <- function(paper){
res$issue <- get_value(".//JournalIssue/Issue")
res$pages <- get_value(".//MedlinePgn")
res$key_words <- get_value(".//DescriptorName")
res$doi <- get_value(".//ArticleId[@IdType='doi']")
res$pmid <- get_value(".//ArticleId[@IdType='pubmed']")
res$doi <- get_value(".//PubmedData/ArticleIdList/ArticleId[@IdType='doi']")
res$pmid <- get_value(".//PubmedData/ArticleIdList/ArticleId[@IdType='pubmed']")
res$abstract <- get_value(".//AbstractText")

structure(res, class="pubmed_record", empty=FALSE)
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test_parse.r
Expand Up @@ -10,6 +10,10 @@ parsed_raw <- parse_pubmed_xml(raw_rec)
parsed_rec <- parse_pubmed_xml(xml_rec)
parsed_multi <- parse_pubmed_xml(multi_rec)

multi_pmid_eg <- parse_pubmed_xml(
entrez_fetch(db="pubmed", id='29743284', rettype="xml")
)

test_that("pubmed file parsers work",{
expect_that(raw_rec, is_a("character"))

Expand All @@ -27,6 +31,12 @@ test_that("pubmed file parsers work",{
# re-introduced there will be 25 authors in each record and this will fail
expect_that(length(parsed_multi[[1]]$authors), equals(1))

# Bug #131 related to extracting all PMIDs from a pubmed xml that contained
# references, not just the one true pm od teh artcle. Testing we don't
# regress

expect_that(length(multi_pmid_eg$pmid), equals(1))

})

test_that("we can print pubmed records", {
Expand Down

0 comments on commit 991c555

Please sign in to comment.