Fix BibTeX Files According to JSS Style Guidelines

Description

Utilities for processing BibTeX files, adding DOIs etc., especially for publications in the Journal of Statistical Software.

Usage

fix_bib(x = NULL, file = x, orig = "_orig.bib",
  bibtool = TRUE, doi = TRUE, shortcites = TRUE, escape = TRUE)

bibtool(tex = NULL, orig = "_orig.bib")

shortcites(x, maxlength = 6)

get_doi(x, minscore = 1.5, type = NULL)
add_doi(x, file = "out.bib", minscore = 1.5)

read_bib(file, ...)

Arguments

x character or bibentry object. If NULL the first BibTeX file in the current working directory is used. If a character is supplied it is read into a bibentry object using read.bib.
file character for output BibTeX file name.
orig character with file name for copy of the original BibTeX file (if any).
bibtool logical. Should bibtool be run first (usually to remove bibentries that are not cited)?
doi logical. Should DOIs be added using get_doi (based on cr_works)?
shortcites logical. Should bibentries with a long author list be reported in a shortcites statement?
escape logical or character. Should encoded text (non-ASCII, e.g., for accent and umlaut characters) be preserved in BibTeX output (FALSE) or escaped by their LaTeX representations (TRUE, default)? Instead of TRUE it is also possible to indicate the encoding of the text (e.g., escape = “UTF-8”) explicitly.
tex character specifying the input LaTeX file.
maxlength numeric. Maximum number of authors for a normal cite (that does not have to be shortened).
minscore numeric. Minimum score that needs to be achieved when querying a DOI.
type character. The reference type (e.g., “journal-article” or “book”) that needs to be matched.
… further arguments passed to read.bib.

Details

The fix_bib function is a utility to automatically bring a .bib file almost into JSS style. By default, it proceeds by reading a .bib file using read.bib, omitting unused entries using bibtool, modifying author names, titles, journals, etc. if necessary, adding DOIs for articles and books using cr_works, and writing the result again to the same .bib file.

Some steps can be switched off by setting the corresponding arguments. Standalone functions for these steps are also provided.

Value

fix_bib and add_doi return an object of class “bibentry” (invisibly if an output file is specified).

bibtool returns a logical, only indicating whether the file renaming worked.

shortcites and get_doi return character vectors with BibTeX keys and DOIs, respectively.

See Also

jss

Examples

library("jss")


bibfile <- system.file("bib", "example.bib", package = "jss")

library("bibtex")

## read BibTeX entry as currently stored
bde1 <- read.bib(bibfile)
print(bde1)
Stefanski L, Boos D (2002). "The calculus of M-estimation." _American
Statistician_, *56*, 29-38.
toBibtex(bde1)
@Article{Stefanski+Boos:2002,
  author = {L.A. Stefanski and D.D. Boos},
  title = {The calculus of {M}-estimation},
  journal = {American Statistician},
  volume = {56},
  year = {2002},
  pages = {29--38},
}
## fix BibTeX entry
## - but do not overwrite file
## - running bibtool is not necessary (and also not possible as there is no .tex file)
## - query the DOI (which takes a couple of seconds)
bde2 <- fix_bib(bibfile, file = FALSE, bibtool = FALSE, doi = TRUE)
print(bde2)
Stefanski LA, Boos DD (2002). "The Calculus of M-Estimation." _The
American Statistician_, *56*, 29-38. doi:10.1198/000313002753631330
<https://doi.org/10.1198/000313002753631330>.
toBibtex(bde2)
@Article{Stefanski+Boos:2002,
  author = {L. A. Stefanski and D. D. Boos},
  title = {The Calculus of {M}-Estimation},
  journal = {The American Statistician},
  volume = {56},
  year = {2002},
  pages = {29--38},
  doi = {10.1198/000313002753631330},
}
## - has a capitalized title,
## - correctly spaces the middle initials,
## - unifies the TAS journal name,
## - added the DOI

## cleanup
file.remove("_orig.bib")
[1] TRUE