fix_bib: Fix BibTeX Files According to JSS Style Guidelines

View source: R/fix_bib.R

fix_bibR Documentation

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)

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)

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?

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.

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

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

if(require("bibtex")) {

## read BibTeX entry as currently stored
bde1 <- read.bib(bibfile)
print(bde1)
toBibtex(bde1)

## fix BibTeX entry
## - but do not overwrite file
## - running bibtool is not necessary (and also not possible as there is no .tex file)
## - querying the DOI is switched off (just to save processing time in this example)
bde2 <- fix_bib(bibfile, file = FALSE, bibtool = FALSE, doi = FALSE)
print(bde2)
toBibtex(bde2)
## This has
## - a capitalized title,
## - correctly spaces the middle initials,
## - unifies the TAS journal name,
## - and the DOI could be added by setting doi = TRUE or manually queried via
## get_doi(bde2)
}

jss documentation built on Sept. 9, 2022, 3:09 p.m.

Related to fix_bib in jss...