diff --git a/DESCRIPTION b/DESCRIPTION index 22cc1ba25f..a33d1f1745 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: knitr Type: Package Title: A General-Purpose Package for Dynamic Report Generation in R -Version: 1.45.1 +Version: 1.45.2 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), person("Abhraneel", "Sarma", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index e7b9dddb11..73eb323113 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # CHANGES IN knitr VERSION 1.46 +## BUG FIXES + +- `write_bib()` generated empty entries for packages without URLs (thanks, @bastistician, #2304). # CHANGES IN knitr VERSION 1.45 diff --git a/R/citation.R b/R/citation.R index d7588304bf..470149e5a3 100644 --- a/R/citation.R +++ b/R/citation.R @@ -86,10 +86,9 @@ write_bib = function( x = setdiff(x, setdiff(xfun::base_pkgs(), 'base')) x = sort(x) bib = sapply(x, function(pkg) { - cite = citation(pkg, auto = if (pkg != 'base') { - meta = packageDescription(pkg, lib.loc = lib.loc) - # don't use the citation() URL if the package has provided its own URL - if (is.null(meta$URL)) return(meta) + meta = packageDescription(pkg, lib.loc = lib.loc) + # don't use the citation() URL if the package has provided its own URL + cite = citation(pkg, auto = if (is.null(meta$URL)) meta else { if (packageURL) meta$Repository = meta$RemoteType = NULL # the package may have provided multiple URLs, in which case we use the # first. We also work around a bug in citation() up to R 4.3.1. The grep