ropensci / bibtex

bibtex parser for R
https://docs.ropensci.org/bibtex/
35 stars 12 forks source link

mismatched keys & citations #21

Closed tphilippi closed 1 year ago

tphilippi commented 5 years ago

In generating a .bib file for my installed packages, I get a mismatch part way through, where the rest of the .bib file has the key assigned to the previous package. A minimum reproducible example:

test <- c("aod", "ape", "aplpack", "aqp", "argosfilter", "bibtex", "knitr") install.packages(test, repos = "https://cloud.r-project.org/") junk <- bibtex::write.bib(test, "bibtex_version.bib")

The jag in bibtex_version.bib is:

@Article{ape, title = {ape 5.0: an environment for modern phylogenetics and evolutionary analyses in {R}}, author = {E. Paradis and K. Schliep}, journal = {Bioinformatics}, year = {2018}, volume = {35}, pages = {526-528}, }

@Manual{aplpack, title = {Algorithms for quantitative pedology: A toolkit for soil scientists}, author = {D.E. debeaudette@ucdavis.edu Beaudette and P. Roudier and A.T. O'Geen}, journal = {Computers & Geosciences}, year = {2013}, volume = {52}, pages = {258 - 268}, url = {http://ncss-tech.github.io/AQP/}, }

@Manual{aqp, title = {argosfilter: Argos locations filter}, author = {Carla Freitas}, year = {2012}, note = {R package version 0.63}, url = {https://CRAN.R-project.org/package=argosfilter}, }

The warnings messages are:

It is recommended to use ‘given’ instead of ‘middle’. Converted 7 of 7 package citations to BibTeX Writing 9 Bibtex entries ... OK Results written to file 'bibtex_version.bib' Warning messages: 1: In structure(x, package = package, class = c("citation", "bibentry")) : Calling 'structure(NULL, )' is deprecated, as NULL cannot have attributes. Consider 'structure(list(), )' instead. 2: In mapply(function(b, k) { : longer argument not a multiple of length of shorter

I have tested in both R 3.5.3 bibtex_0.4.2 and R 3.6.0 bibtex_0.4.2 The similar knitr::write_bib() function does not generate this mis-match of keys, but it pulls very different information from the package info.

I think the problem may be in the CITATION file for aplpack, which is a quoted bibentry, not p1 p2 citHeader() citEntry() textVersion as for most other packages.

"bibentry(bibtype = Manual," " title = {{aplpack}: Another Plot Package (version 180312)}," " author = {Hans Peter Wolf}," " year = {2018}," " url = https://cran.r-project.org/package=aplpack)"

I will contact that package's maintainers, but since that version made it past the package checkers, it might be nice to add some error trapping to this package, too.

Also, note that citation('aplpack') fails:

citation('aplpack') Warning message: In structure(x, package = package, class = c("citation", "bibentry")) : Calling 'structure(NULL, )' is deprecated, as NULL cannot have attributes. Consider 'structure(list(), )' instead.

tphilippi commented 5 years ago

by renaming aplpack/CITATION to aplpack/xCITATION I prevent this issue. So perhaps CRAN doesn't check for valid CITATION files in packages. I've asked the maintainer of aplpack to fix or delete the problematic CITATION file. However, the source .tar.gz for aplpack does not include a CITATION file, so I don't even know if the package owner or something in the process of generating windows binaries generated that problematic CITATION file.

This clearly isn't fundamentally a problem with bibtex, as the same package bombs citation(). However, because it can have huge but hidden consequences (mismatched key vs package for all packages after alphabetically aplpack), it there's an easy way to trap this error in bibtex::write.bib(), that could save other users hard to detect problems.

coatless commented 1 year ago

@tphilippi thanks for registering the concern. We recently changed the bibtex parser to use R instead of C.