Parse standard BibTeX (.bib) files into an sm_corpus object.
Extracts entry type, title, author, year, DOI, journal, abstract, volume,
pages, and keywords from each @type{key, ...} entry.
Usage
sm_read_bib(
path,
encoding = "UTF-8",
engine = c("native", "bibliometrix", "auto"),
verbose = TRUE,
call = rlang::caller_env()
)Arguments
- path
Character scalar. Path to a
.bibfile.- 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).- verbose
Logical. Print progress messages?
- call
Caller environment for error reporting.
Value
An sm_corpus object.
Implementation
The native parser follows the BibTeX format specification as described in
the original BibTeX documentation (Patashnik, 1988). Field values may be
enclosed in braces or double-quotes and may span multiple lines. String
concatenation with # is not supported; @string and @preamble
entries are skipped.
Protective braces are removed from titles, journals, abstracts, keywords
and DOIs; escaped braces remain literal. Common LaTeX accent commands
(\", \', \^, \~, \=, \., \c, \v, \u,
\H, \k, \r, and backslash followed by a grave accent) decode
to precomposed letters where available, else the bare letter.
Letter commands \ss, \o, \O, \aa, \AA,
\ae, \AE, \oe, \OE, \l, \L and \i also decode, as do
\&, \%, \$, \# and \_. DOI cleaning only removes braces
and decodes those five escapes. Ties (~), -- and math expressions
remain as written. Whitespace outside math is collapsed and trimmed.
Only a lowercase and outside braces separates authors; a comma outside
braces flips a name from surname-first to given-name-first. Braced
corporate names stay together, and a trailing and others is retained.
Quoted field values end only at a quote outside braces. The first
isolated four-digit year (1000–2999) in year is used, falling back to
the BibLaTeX date field when no such year is present.
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_bib(sm_example_files("example.bib"), verbose = FALSE)
corpus
#>
#> ── <sm_corpus> ─────────────────────────────────────────────────────────────────
#> Works: 3 | Authors: 9 | Institutions: 0
#> Years: 2022 - 2024
#> Sources (journals): 2
#> Embeddings: none
#> Provenance: bibtex (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 10.1… Spat… Spatial… 2023 arti… S0000000… NA NA
#> 2 W000000002 10.1… Mach… We deve… 2022 inpr… S0000000… NA NA
#> 3 W000000003 10.1… Atla… This co… 2024 book NA NA NA
#> # ℹ 7 more variables: language <chr>, pmid <chr>, arxiv_id <chr>,
#> # openalex_id <chr>, is_retracted <lgl>, retraction_date <date>,
#> # last_refreshed <dttm>