write_bib: Generate BibTeX bibliography databases for R packages

Description Usage Arguments Details Value Note Author(s) Examples

View source: R/citation.R

Description

This function uses citation and toBibtex to create bib entries for R packages and write them in a file. It 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

1
2
3
4
5
6
7
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, or if NULL, output is written to the R console.

tweak

Whether to fix some known problems in the citations, especially non-standard format of author names.

width

Width of lines in bibliography entries. If NULL, lines will not be wrapped.

prefix

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

Details

For a package, the keyword R-pkgname is used for its bib item, where pkgname is the name of the package. Citation entries specified in the ‘CITATION’ file of the package are also included. 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, ...).

Value

A list containing the citations. Citations are also written to the file as a side effect.

Note

Some packages on CRAN do not have standard bib entries, which was once reported by Michael Friendly at https://stat.ethz.ch/pipermail/r-devel/2010-November/058977.html. I find this a real pain, and there are no easy solutions except contacting package authors to modify their DESCRIPTION files. Anyway, the argument tweak has provided ugly hacks to deal with packages which are known to be non-standard in terms of the format of citations; tweak = TRUE is by no means intended to hide or modify the original citation information. It is just due to the loose requirements on package authors for the DESCRIPTION file. On one hand, I apologize if it really mangles the information about certain packages; on the other, I strongly recommend package authors to consider the [email protected] field (see the manual Writing R Extensions) to make it easier for other people to cite R packages. See knitr:::.tweak.bib for details of tweaks. Also note this is subject to future changes since R packages are being updated. If you want to contribute more tweaks, please edit the file ‘inst/misc/tweak_bib.csv’ in the source package.

Author(s)

Yihui Xie and Michael Friendly

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
write_bib(c("RGtk2", "gWidgets"), file = "R-GUI-pkgs.bib")
unlink("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)

Example output

tweaking gWidgets
tweaking rgl
@Manual{R-animation,
  title = {animation: A Gallery of Animations in Statistics and Utilities to Create
Animations},
  author = {Yihui Xie},
  year = {2018},
  note = {R package version 2.6},
  url = {https://CRAN.R-project.org/package=animation},
}
@Manual{R-ggplot2,
  title = {ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics},
  author = {Hadley Wickham and Winston Chang and Lionel Henry and Thomas Lin Pedersen and Kohske Takahashi and Claus Wilke and Kara Woo},
  year = {2019},
  note = {R package version 3.1.1},
  url = {https://CRAN.R-project.org/package=ggplot2},
}
@Manual{R-knitr,
  title = {knitr: A General-Purpose Package for Dynamic Report Generation in R},
  author = {Yihui Xie},
  year = {2019},
  note = {R package version 1.22},
  url = {https://CRAN.R-project.org/package=knitr},
}
@Manual{R-rgl,
  title = {rgl: 3D Visualization Using OpenGL},
  author = {Daniel Adler and Duncan Murdoch},
  year = {2016},
  note = {R package version 0.96.0},
  url = {https://CRAN.R-project.org/package=rgl},
}
@Manual{R-MASS,
  title = {MASS: Support Functions and Datasets for Venables and Ripley's MASS},
  author = {Brian Ripley},
  year = {2019},
  note = {R package version 7.3-51.4},
  url = {https://CRAN.R-project.org/package=MASS},
}
@Manual{R-base,
  title = {R: A Language and Environment for Statistical Computing},
  author = {{R Core Team}},
  organization = {R Foundation for Statistical Computing},
  address = {Vienna, Austria},
  year = {2018},
  url = {https://www.R-project.org/},
}
@Manual{cluster,
  title = {cluster: "Finding Groups in Data": Cluster Analysis Extended Rousseeuw et
al.},
  author = {Martin Maechler and Peter Rousseeuw and Anja Struyf and Mia Hubert},
  year = {2019},
  note = {R package version 2.0.9},
  url = {https://CRAN.R-project.org/package=cluster},
}
tweaking digest
@Manual{R-pkg-digest,
  title = {digest: Create Compact Hash Digests of R Objects},
  author = {Dirk Eddelbuettel},
  year = {2018},
  note = {R package version 0.6.18},
  url = {https://CRAN.R-project.org/package=digest},
}
@Manual{R-digest,
  title = {digest: Create Compact Hash Digests of R Objects},
  author = {Dirk Eddelbuettel with contributions by Antoine Lucas and Jarek Tuszynski and Henrik Bengtsson and Simon Urbanek and Mario Frasca and Bryan Lewis and Murray Stokely and Hannes Muehleisen and Duncan Murdoch and Jim Hester and Wush Wu and Qiang Kou and Thierry Onkelinx and Michel Lang and Viliam Simko and Kurt Hornik and Radford Neal.},
  year = {2018},
  note = {R package version 0.6.18},
  url = {https://CRAN.R-project.org/package=digest},
}
List of 43
 $ BiplotGUI    : Named chr "  author = {Anthony la Grange and  N. J. le Roux and P.J. Rousseeuw and I. Ruts and J. W. Tukey},"
  ..- attr(*, "names")= chr "author"
 $ CircStats    : Named chr "  author = {Ulric Lund and Claudio Agostinelli},"
  ..- attr(*, "names")= chr "author"
 $ ElemStatLearn: Named chr "  author = {Kjetil Halvorsen},"
  ..- attr(*, "names")= chr "author"
 $ Fahrmeir     : Named chr "  author = {Kjetil Halvorsen},"
  ..- attr(*, "names")= chr "author"
 $ Hmisc        : Named chr "  author = {Harrell, Jr., Frank E},"
  ..- attr(*, "names")= chr "author"
 $ Hmisc        : Named chr "  author = {Frank E. {Harrell, Jr.}},"
  ..- attr(*, "names")= chr "author"
 $ R2SWF        : Named chr "  author = {Yixuan Qiu and Yihui Xie and Cameron Bracken},"
  ..- attr(*, "names")= chr "author"
 $ R2WinBUGS    : Named chr "  author = {Andrew Gelman and Sibylle Sturtz and Uwe Ligges and Gregor Gorjanc and Jouni Kerman},"
  ..- attr(*, "names")= chr "author"
 $ RODBC        : Named chr "  author = {Brian Ripley and Michael Lapsley},"
  ..- attr(*, "names")= chr "author"
 $ RgoogleMaps  : Named chr "  author = {Markus Loecher},"
  ..- attr(*, "names")= chr "author"
 $ Sleuth2      : Named chr "  author = {F. L. Ramsey and D. W. Schafer and Jeannie Sifneos and Berwin A. Turlach},"
  ..- attr(*, "names")= chr "author"
 $ ade4         : Named chr "  author = {St\303\251phane Dray and Anne-B\303\251atrice Dufour and Jean Thioulouse and Thibaut Jombart and Sandrine Pavoine a
  ..- attr(*, "names")= chr "author"
 $ akima        : Named chr "  author = {H. Akima and Albrecht Gebhardt and Thomas Petzoldt and Martin Maechler},"
  ..- attr(*, "names")= chr "author"
 $ ash          : Named chr "  author = {David W. Scott and Albrecht Gebhardt and Stephen Kaluzny},"
  ..- attr(*, "names")= chr "author"
 $ bcpa         : Named chr "  author = {Jose Claudio Faria and Clarice Garcia Borges Demetrio},"
  ..- attr(*, "names")= chr "author"
 $ bitops       : Named chr "  author = {Steve Dutky and Martin Maechler},"
  ..- attr(*, "names")= chr "author"
 $ cacheSweave  : Named chr "  author = {Roger D. Peng},"
  ..- attr(*, "names")= chr "author"
 $ cat          : Named chr "  author = {Ted Harding and Fernando Tusell and Joseph L. Schafer},"
  ..- attr(*, "names")= chr "author"
 $ contrast     : Named chr "  author = {Max Kuhn and Steve Weston and Jed Wing and James Forester},"
  ..- attr(*, "names")= chr "author"
 $ date         : Named chr "  author = {Terry Therneau and Thomas Lumley and Kjetil Halvorsen and Kurt Hornik},"
  ..- attr(*, "names")= chr "author"
 $ digest       : Named chr "  author = {Dirk Eddelbuettel},"
  ..- attr(*, "names")= chr "author"
 $ epiR         : Named chr "  author = {Mark Stevenson and Telmo Nunes and Cord Heuer and Jonathon Marshall and Javier Sanchez and Ron Thor"| __truncated__
  ..- attr(*, "names")= chr "author"
 $ flashClust   : Named chr "  author = {Fionn Murtagh and {R development team} and Peter Langfelder},"
  ..- attr(*, "names")= chr "author"
 $ foreach      : Named chr "  author = {{Revolution Analytics} and Steve Weston}},"
  ..- attr(*, "names")= chr "author"
 $ fortunes     : Named chr "  author = {Achim Zeileis and the R community},"
  ..- attr(*, "names")= chr "author"
 $ gWidgets     : Named chr "  author = {John Verzani},"
  ..- attr(*, "names")= chr "author"
 $ gee          : Named chr "  author = {Vincent J Carey and Thomas Lumley and Brian Ripley},"
  ..- attr(*, "names")= chr "author"
 $ gmodels      : Named chr "  author = {Gregory R. Warnes andBen Bolker and Thomas Lumley and Randall C Johnson and Randall C. Johnson},"
  ..- attr(*, "names")= chr "author"
 $ hexbin       : Named chr "  author = {Dan Carr and Nicholas Lewin-Koh and Martin Maechler},"
  ..- attr(*, "names")= chr "author"
 $ leaps        : Named chr "  author = {Thomas Lumley},"
  ..- attr(*, "names")= chr "author"
 $ mapproj      : Named chr "  author = {Doug McIlroy and Ray Brownrigg and Thomas P Minka and Roger Bivand},"
  ..- attr(*, "names")= chr "author"
 $ maps         : Named chr "  author = {Ray Brownrigg},"
  ..- attr(*, "names")= chr "author"
 $ mathgraph    : Named chr "  author = {Patrick J. Burns and Nick Efthymiou and Claus Dethlefsen},"
  ..- attr(*, "names")= chr "author"
 $ oz           : Named chr "  author = {Bill Venables and Kurt Hornik},"
  ..- attr(*, "names")= chr "author"
 $ pbivnorm     : Named chr "  author = {Alan Genz and Brenton Kenkel},"
  ..- attr(*, "names")= chr "author"
 $ pscl         : Named chr "  author = {Simon Jackman and Alex Tahk and Achim Zeileis and Christina Maimone and Jim Fearon},"
  ..- attr(*, "names")= chr "author"
 $ quadprog     : Named chr "  author = {Berwin A. Turlach and Andreas Weingessel},"
  ..- attr(*, "names")= chr "author"
 $ randomForest : Named chr "  author = {Leo Breiman and Adele Cutler and Andy Liaw and Matthew Wiener},"
  ..- attr(*, "names")= chr "author"
 $ rgl          : Named chr "  author = {Daniel Adler and Duncan Murdoch},"
  ..- attr(*, "names")= chr "author"
 $ rms          : Named chr "  author = {Frank E. {Harrell, Jr.}},"
  ..- attr(*, "names")= chr "author"
 $ robustbase   : Named chr "  author = {Valentin Todorov and Andreas Ruckstuhl and Matias Salibian-Barrera and Tobias Verbeke and Manuel Ko"| __truncated__
  ..- attr(*, "names")= chr "author"
 $ sm           : Named chr "  author = {Adrian Bowman and Adelchi Azzalini},"
  ..- attr(*, "names")= chr "author"
 $ tuneR        : Named chr "  author = {Uwe Ligges},"
  ..- attr(*, "names")= chr "author"

knitr documentation built on Feb. 7, 2020, 1:06 a.m.