bibtex icon indicating copy to clipboard operation
bibtex copied to clipboard

write.bib chooses the wrong citation, and doesn't warn that there was an option

Open SamBuckman opened this issue 4 years ago • 3 comments

Some of the packages in R have multiple citations associated with them. For example knitr::write_bib("testthat") returns

@Manual{R-testthat, title = {testthat: Unit Testing for R}, author = {Hadley Wickham}, year = {2021}, note = {R package version 3.0.2}, url = {https://CRAN.R-project.org/package=testthat}, }

@Article{testthat2011, author = {Hadley Wickham}, title = {testthat: Get Started with Testing}, journal = {The R Journal}, year = {2011}, volume = {3}, pages = {5--10}, url = {https://journal.r-project.org/archive/2011-1/RJournal_2011-1_Wickham.pdf}, }

The first one is the citation for the package, so it's the one I want. But bibtex::write.bib("testthat") gives the second one, and doesn't warn that it's doing it.

SamBuckman avatar Jun 03 '21 23:06 SamBuckman

knitr::write_bib appears to get a citation for the package derived from the DESCRIPTION file + use any citations from an optional CITATION file

whereas write.bib here does not generate the @Manual citation since if there's a CITATION file in the package, then utils::citation only gets the citation in that file

sckott avatar Jun 08 '21 17:06 sckott

Wonder if bibtex should change to follow what knitr::write_bib does or not

sckott avatar Jun 08 '21 17:06 sckott

One option would be to give bibtex::write.bib() an additional argument ... and pass that to

bibs <- sapply(pkgs, function(x) try(citation(x, ...)), simplify = FALSE)

Then you can do

bibtex::write.bib("testthat", auto = TRUE)

which generates the "auto" citation from the DESCRIPTION file

@Manual{testthat,
  title = {testthat: Unit Testing for R},
  author = {Hadley Wickham},
  year = {2021},
  note = {R package version 3.0.4},
  url = {https://CRAN.R-project.org/package=testthat},
}

zeileis avatar Oct 22 '21 06:10 zeileis