knitr (version 1.17)

write_bib: Generate BibTeX bibliography databases for R packages

Description

This function uses citation and toBibtex to create bib entries for R packages and write them in a file. Only the auto-generated citations are included for a package. This function can facilitate the auto-generation of bibliography databases for R packages, and it is easy to regenerate all the citations after updating R packages.

Usage

write_bib(x = .packages(), file = "", tweak = TRUE, width = NULL, 
    prefix = getOption("knitr.bib.prefix", "R-"))

Arguments

x

package names (packages which are not installed are ignored)

file

the (.bib) file to write (by default writes to the R console; ignored if it is NULL)

tweak

whether to fix some known problems in the citations, especially non-standard format of authors

width

the width of lines in bibliographyb entries (if NULL, lines will not be wrapped)

prefix

a prefix string for keys in BibTeX entries; by default, it is R- unless option('knitr.bib.prefix') has been set to another string

Value

a list containing the citations (also written to the file as a side effect)

Details

The citation is forced to be generated from the DESCRIPTION file of the package (citation(auto = TRUE)). The keyword R-pkgname is used for the bib item, where pkgname is the name of the package. All references specified in the CITATION file of the package are ignored. The main purpose of this function is to automate the generation of the package citation information because it often changes (e.g. author, year, package version, ...). By comparison, paper/book citations don't change too often, so it is not a lot of work even if you just cut and paste such bibliography entries from toBibtex(citation()).

Examples

Run this code
# NOT RUN {
write_bib(c("RGtk2", "gWidgets"), file = "R-GUI-pkgs.bib")
write_bib(c("animation", "rgl", "knitr", "ggplot2"))
write_bib(c("base", "parallel", "MASS"))  # base and parallel are identical
write_bib("cluster", prefix = "")  # a empty prefix
write_bib("digest", prefix = "R-pkg-")  # a new prefix
write_bib("digest", tweak = FALSE)  # original version

# what tweak=TRUE does
str(knitr:::.tweak.bib)
# }

Run the code above in your browser using DataCamp Workspace