Parse PubMed XML export files (NCBI DTD format) into an sm_corpus
object. Extracts article metadata from PubmedArticle nodes including
PMID, title, abstract, journal, authors, MeSH terms, DOI, and
publication type.
Usage
sm_read_pubmed_xml(
path,
encoding = "UTF-8",
engine = c("native", "bibliometrix", "auto"),
verbose = TRUE,
call = rlang::caller_env()
)Arguments
- path
Character scalar. Path to a PubMed XML file.
- encoding
Character scalar. File encoding (default
"UTF-8").- engine
Character scalar. One of
"native"(built-in parser using xml2),"bibliometrix"(delegate tobibliometrix::convert2df()), or"auto"(try bibliometrix first, fall back to native).- verbose
Logical. Print progress messages?
- call
Caller environment for error reporting.
Value
An sm_corpus object.
Implementation
The native parser uses xml2::read_xml() to parse the NCBI PubMed XML
DTD. Each PubmedArticle element is processed to extract:
MedlineCitation/PMIDfor the PubMed identifierMedlineCitation/Article/ArticleTitlefor the titleMedlineCitation/Article/Abstract/AbstractTextfor the abstract (multiple sections are concatenated)MedlineCitation/Article/Journal/Titleand/ISSNfor the journalMedlineCitation/Article/Journal/JournalIssue/PubDate/Yearfor yearMedlineCitation/Article/AuthorList/Authorfor authorsMedlineCitation/MeshHeadingList/MeshHeadingfor MeSH terms; the conceptscoreis 1 for a major topic of the article (MajorTopicYNon the descriptor or one of its qualifiers) and 0 otherwisePubmedData/ArticleIdList/ArticleId[@IdType='doi']for DOIMedlineCitation/Article/PublicationTypeListfor document type
References
Aria, M. & Cuccurullo, C. (2017). bibliometrix: An R-tool for comprehensive science mapping analysis. Journal of Informetrics, 11(4), 959–975. doi:10.1016/j.joi.2017.08.007
Examples
corpus <- sm_read_pubmed_xml(sm_example_files("example_pubmed.xml"), verbose = FALSE)
corpus
#>
#> ── <sm_corpus> ─────────────────────────────────────────────────────────────────
#> Works: 3 | Authors: 9 | Institutions: 0
#> Years: 2022 - 2024
#> Sources (journals): 3
#> Embeddings: none
#> Provenance: pubmed (3)
#> Status: Unlocked (last refreshed: never)
head(corpus$works)
#> # A tibble: 3 × 16
#> work_id doi title abstract year type source_id cited_by_count oa_status
#> <chr> <chr> <chr> <chr> <int> <chr> <chr> <int> <chr>
#> 1 W000000001 NA Spat… Spatial… 2023 NA S0000000… NA NA
#> 2 W000000002 NA Mach… We deve… 2022 NA S0000000… NA NA
#> 3 W000000003 NA Comp… This st… 2024 NA S0000000… NA NA
#> # ℹ 7 more variables: language <chr>, pmid <chr>, arxiv_id <chr>,
#> # openalex_id <chr>, is_retracted <lgl>, retraction_date <date>,
#> # last_refreshed <dttm>