Detect the bibliographic file format from the file extension and content, then dispatch to the appropriate reader function.
Usage
sm_read_auto(
path,
encoding = "UTF-8",
engine = c("native", "bibliometrix", "auto"),
verbose = TRUE,
call = rlang::caller_env()
)Arguments
- path
Character scalar. Path to a bibliographic file.
- encoding
Character scalar. File encoding (default
"UTF-8").- engine
Character scalar. One of
"native"(built-in parser),"bibliometrix"(delegate tobibliometrix::convert2df()), or"auto"(try bibliometrix first, fall back to native). Passed through to the selected reader. Ignored for formats without engine support (OpenAlex JSON, Zotero, EndNote XML).- verbose
Logical. Print progress messages?
- call
Caller environment for error reporting.
Value
An sm_corpus object.
Implementation
Format detection proceeds in two stages:
Extension-based:
.bib(BibTeX),.ris(RIS),.json/.jsonl(OpenAlex JSON),.xml(PubMed XML or EndNote XML).Content-based: For
.csv,.tsv, and.txtfiles, the first few lines are inspected for format-specific signatures:WoS plaintext: begins with
FNorPTtagsWoS tab-delimited: header contains PT, AU, TI and UT; also detected in
.tabfiles and files without an extensionScopus CSV: contains
EIDcolumn headerLens CSV: contains
Lens IDcolumn headerDimensions CSV: contains
Dimensions IDorPubYearheaderCochrane CSV: contains
Cochranein header or record-like structureZotero CSV: contains
KeyandItem TypecolumnsRIS-format content in non-
.risfiles
For XML files, the parsed root distinguishes PubMed XML
(PubmedArticleSet, PubmedArticle, PubmedBookArticleSet) from
EndNote XML (xml/records or records). Unknown roots are unsupported;
malformed XML raises a file-reading error.
For .nbib and .enw, the first 20 lines determine the content: RIS
records are accepted, but MEDLINE text (PMID- in .nbib, .txt or
files without extensions) and Refer text (% tags in .enw) are not
supported. Export MEDLINE records as PubMed XML, or use
sm_fetch_pubmed(); export Refer libraries as RIS or EndNote XML.
A leading UTF-8 BOM is ignored for text format detection.
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
# The format is detected from the file content and extension.
corpus <- sm_read_auto(sm_example_files("example.bib"), verbose = FALSE)
corpus$metadata$reader
#> [1] "sm_read_bib"
corpus <- sm_read_auto(sm_example_files("example_scopus.csv"),
verbose = FALSE)
corpus$metadata$reader
#> [1] "sm_read_scopus"