Generates a Bibtex file from a list of packages or all the installed packages. It is useful for adding relevant citations in Sweave documents.

write.pkgbib(
  entry = NULL,
  file = "Rpackages.bib",
  prefix = "",
  append = FALSE,
  verbose = TRUE
)

Arguments

entry

a bibentry object or a character vector of package names. If NULL, then the list of all installed packages is used.

file

output Bibtex file. It can be specified as a filename (as a single character string), NULL for stdout, or a link{connection} object. If file is a character string, an extension '.bib' is appended if not already present.

prefix

character string to prepend to the generated packages' Bibtex key.

append

a logical that indicates that the Bibtex entries should be added to the file. If FALSE (default), the file is overwritten.

verbose

a logical to toggle verbosity. If file=NULL, verbosity is forced off.

Value

the list of Bibtex objects -- invisibly.

Details

Multiple citations are handled by adding a numeric suffix to the Bibtex key (other than the first/main citation) as "<pkgname>%i" (e.g. pkg, pkg2, pkg3).

Note

The Old version of this function write.bib has now been integrated by Romain Francois in the bibtex package.

References

Creating bibtex file of all installed packages? Achim Zeileis. R-help mailing list. https://stat.ethz.ch/pipermail/r-help/2009-December/415181.html

See also

link{connection}, link{bibentry}

Author

Renaud Gaujoux, based on the function Rpackages.bib from Achim Zeileis (see References).

Examples

write.pkgbib(c('rbibutils', 'utils', 'tools'), file='references')
#> Converted 3 of 3 package citations to BibTeX
#> Writing 3 Bibtex entries ...
#> OK #> Results written to file 'references.bib'
bibs <- rbibutils::readBib('references.bib', "UTF-8")
#> #> count_type: #> #> no_type not_char Manual #> 0 0 3 #> #>
write.pkgbib(bibs, 'references2.bib')
#> Writing 3 Bibtex entries ...
#> OK #> Results written to file 'references2.bib'
bibs2 <- rbibutils::readBib('references.bib', "UTF-8")
#> #> count_type: #> #> no_type not_char Manual #> 0 0 3 #> #>
identical(bibs, bibs2)
#> [1] TRUE
stopifnot(identical(bibs, bibs2)) # write to stdout() write.pkgbib(c('rbibutils', 'utils', 'tools'), file=NULL)
#> @Manual{rbibutils, #> title = {rbibutils: Convert Between Bibliography Formats}, #> author = {Georgi N. Boshnakov and Chris Putman}, #> year = {2020}, #> note = {R package version 1.3}, #> url = {https://CRAN.R-project.org/package=rbibutils}, #> } #> #> @Manual{utils, #> title = {R: A Language and Environment for Statistical Computing}, #> author = {{R Core Team}}, #> organization = {R Foundation for Statistical Computing}, #> address = {Vienna, Austria}, #> year = {2020}, #> url = {https://www.R-project.org/}, #> } #> #> @Manual{tools, #> title = {R: A Language and Environment for Statistical Computing}, #> author = {{R Core Team}}, #> organization = {R Foundation for Statistical Computing}, #> address = {Vienna, Austria}, #> year = {2020}, #> url = {https://www.R-project.org/}, #> }
# clean up unlink(c('references.bib', 'references2.bib'))